19
19
import os
20
20
import sys
21
21
import re
22
+ import subprocess
22
23
23
24
CLASSIFIERS = """\
24
25
Development Status :: 5 - Production/Stable
53
54
ISRELEASED = False
54
55
VERSION = '%d.%d.%d' % (MAJOR , MINOR , MICRO )
55
56
56
- # Return the svn version as a string (copied from setuptools)
57
- def svn_revision ():
58
- from numpy .distutils import log
59
- revision = 0
60
- urlre = re .compile ('url="([^"]+)"' )
61
- revre = re .compile ('committed-rev="(\d+)"' )
62
-
63
- for base ,dirs ,files in os .walk (os .curdir ):
64
- if '.svn' not in dirs :
65
- dirs [:] = []
66
- continue # no sense walking uncontrolled subdirs
67
- dirs .remove ('.svn' )
68
- f = open (os .path .join (base ,'.svn' ,'entries' ))
69
- data = f .read ()
70
- f .close ()
71
-
72
- if data .startswith ('9' ) or data .startswith ('8' ):
73
- data = map (str .splitlines ,data .split ('\n \x0c \n ' ))
74
- del data [0 ][0 ] # get rid of the '8' or '9'
75
- dirurl = data [0 ][3 ]
76
- localrev = max ([int (d [9 ]) for d in data if len (d )> 9 and d [9 ]]+ [0 ])
77
- elif data .startswith ('<?xml' ):
78
- dirurl = urlre .search (data ).group (1 ) # get repository URL
79
- localrev = max ([int (m .group (1 )) for m in revre .finditer (data )]+ [0 ])
80
- else :
81
- log .warn ("unrecognized .svn/entries format; skipping %s" , base )
82
- dirs [:] = []
83
- continue
84
- if base == os .curdir :
85
- base_url = dirurl + '/' # save the root url
86
- elif not dirurl .startswith (base_url ):
87
- dirs [:] = []
88
- continue # not part of the same svn tree, skip it
89
- revision = max (revision , localrev )
90
-
91
- return str (revision )
57
+ # Return the svn version as a string, raise a ValueError otherwise
58
+ def svn_version ():
59
+ try :
60
+ out = subprocess .Popen (['svn' , 'info' ], stdout = subprocess .PIPE ).communicate ()[0 ]
61
+ except OSError :
62
+ print " --- Could not run svn info --- "
63
+ return ""
64
+
65
+ r = re .compile ('Revision: ([0-9]+)' )
66
+ svnver = None
67
+ for line in out .split ('\n ' ):
68
+ m = r .match (line )
69
+ if m :
70
+ svnver = m .group (1 )
71
+
72
+ if not svnver :
73
+ raise ValueError ("Error while parsing svn version ?" )
74
+ return svnver
92
75
93
76
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
94
77
# update it when the contents of directories change.
@@ -105,7 +88,7 @@ def svn_revision():
105
88
FULLVERSION += '.dev'
106
89
# If in git or something, bypass the svn rev
107
90
if os .path .exists ('.svn' ):
108
- FULLVERSION += svn_revision ()
91
+ FULLVERSION += svn_version ()
109
92
110
93
def write_version_py (filename = 'numpy/version.py' ):
111
94
cnt = """
0 commit comments