59
59
ISRELEASED = False
60
60
VERSION = '%d.%d.%d' % (MAJOR , MINOR , MICRO )
61
61
62
- # Return the svn version as a string, raise a ValueError otherwise
63
- def svn_version ():
62
+ # Return the git revision as a string
63
+ def git_version ():
64
64
def _minimal_ext_cmd (cmd ):
65
65
# construct minimal environment
66
66
env = {}
@@ -72,30 +72,17 @@ def _minimal_ext_cmd(cmd):
72
72
env ['LANGUAGE' ] = 'C'
73
73
env ['LANG' ] = 'C'
74
74
env ['LC_ALL' ] = 'C'
75
- out = subprocess .Popen (cmd ,
76
- stdout = subprocess . PIPE , env = env ).communicate ()[0 ]
75
+ out = subprocess .Popen (cmd , stdout = subprocess . PIPE ,
76
+ env = env ).communicate ()[0 ]
77
77
return out
78
78
79
79
try :
80
- out = _minimal_ext_cmd (['svn' , 'info' ])
80
+ out = _minimal_ext_cmd (['git' , 'rev-parse' , 'HEAD' ])
81
+ GIT_REVISION = out .strip ().decode ('ascii' )
81
82
except OSError :
82
- print (" --- Could not run svn info --- " )
83
- return ""
83
+ GIT_REVISION = "Unknown"
84
84
85
- r = re .compile ('Revision: ([0-9]+)' )
86
- svnver = ""
87
-
88
- out = out .decode ()
89
-
90
- for line in out .split ('\n ' ):
91
- m = r .match (line .strip ())
92
- if m :
93
- svnver = m .group (1 )
94
-
95
- if not svnver :
96
- print ("Error while parsing svn version" )
97
-
98
- return svnver
85
+ return GIT_REVISION
99
86
100
87
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
101
88
# update it when the contents of directories change.
@@ -107,36 +94,36 @@ def _minimal_ext_cmd(cmd):
107
94
# a lot more robust than what was previously being used.
108
95
builtins .__NUMPY_SETUP__ = True
109
96
110
- FULLVERSION = VERSION
111
- if not ISRELEASED :
112
- FULLVERSION += '.dev'
113
- # If in git or something, bypass the svn rev
114
- if os .path .exists ('.svn' ):
115
- FULLVERSION += svn_version ()
116
-
117
97
def write_version_py (filename = 'numpy/version.py' ):
118
98
cnt = """
119
99
# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
120
- short_version='%(version)s'
121
- version='%(version)s'
122
- release=%(isrelease)s
100
+ short_version = '%(version)s'
101
+ version = '%(version)s'
102
+ full_version = '%(full_version)s'
103
+ git_revision = '%(git_revision)s'
104
+ release = %(isrelease)s
123
105
124
106
if not release:
125
- version += '.dev'
126
- import os
127
- svn_version_file = os.path.join(os.path.dirname(__file__),
128
- 'core','__svn_version__.py')
129
- if os.path.isfile(svn_version_file):
130
- import imp
131
- svn = imp.load_module('numpy.core.__svn_version__',
132
- open(svn_version_file),
133
- svn_version_file,
134
- ('.py','U',1))
135
- version += svn.version
107
+ version = full_version
136
108
"""
109
+ FULL_VERSION = VERSION
110
+ if not ISRELEASED :
111
+ if os .path .exists ('.git' ):
112
+ GIT_REVISION = git_version ()
113
+ elif os .path .exists (filename ):
114
+ # must be a source distribution, use existing version file
115
+ from numpy .version import git_revision as GIT_REVISION
116
+ else :
117
+ GIT_REVISION = "Unknown"
118
+
119
+ FULL_VERSION += '.dev-' + GIT_REVISION [:7 ]
120
+
137
121
a = open (filename , 'w' )
138
122
try :
139
- a .write (cnt % {'version' : VERSION , 'isrelease' : str (ISRELEASED )})
123
+ a .write (cnt % {'version' : VERSION ,
124
+ 'full_version' : FULL_VERSION ,
125
+ 'git_revision' : GIT_REVISION ,
126
+ 'isrelease' : str (ISRELEASED )})
140
127
finally :
141
128
a .close ()
142
129
0 commit comments