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 = {}
@@ -76,25 +76,12 @@ def _minimal_ext_cmd(cmd):
76
76
return out
77
77
78
78
try :
79
- out = _minimal_ext_cmd (['svn' , 'info' ])
79
+ out = _minimal_ext_cmd (['git' , 'rev-parse' , 'HEAD' ])
80
+ GIT_REVISION = out .strip ()
80
81
except OSError :
81
- print (" --- Could not run svn info --- " )
82
- return ""
82
+ GIT_REVISION = "Unknwn"
83
83
84
- r = re .compile ('Revision: ([0-9]+)' )
85
- svnver = ""
86
-
87
- out = out .decode ()
88
-
89
- for line in out .split ('\n ' ):
90
- m = r .match (line .strip ())
91
- if m :
92
- svnver = m .group (1 )
93
-
94
- if not svnver :
95
- print ("Error while parsing svn version" )
96
-
97
- return svnver
84
+ return GIT_REVISION
98
85
99
86
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
100
87
# update it when the contents of directories change.
@@ -106,36 +93,37 @@ def _minimal_ext_cmd(cmd):
106
93
# a lot more robust than what was previously being used.
107
94
builtins .__NUMPY_SETUP__ = True
108
95
109
- FULLVERSION = VERSION
110
- if not ISRELEASED :
111
- FULLVERSION += '.dev'
112
- # If in git or something, bypass the svn rev
113
- if os .path .exists ('.svn' ):
114
- FULLVERSION += svn_version ()
115
-
116
96
def write_version_py (filename = 'numpy/version.py' ):
117
97
cnt = """
118
98
# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
119
99
short_version='%(version)s'
120
100
version='%(version)s'
101
+ full_version='%(full_version)s'
102
+ git_revision='%(git_revision)s'
121
103
release=%(isrelease)s
122
104
123
105
if not release:
124
- version += '.dev'
125
- import os
126
- svn_version_file = os.path.join(os.path.dirname(__file__),
127
- 'core','__svn_version__.py')
128
- if os.path.isfile(svn_version_file):
129
- import imp
130
- svn = imp.load_module('numpy.core.__svn_version__',
131
- open(svn_version_file),
132
- svn_version_file,
133
- ('.py','U',1))
134
- version += svn.version
106
+ version = full_version
135
107
"""
108
+ FULL_VERSION = VERSION
109
+ if not ISRELEASED :
110
+ FULL_VERSION += '.dev'
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 = "Unknwn"
118
+
119
+ FULL_VERSION += GIT_REVISION [:6 ]
120
+
136
121
a = open (filename , 'w' )
137
122
try :
138
- 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 )})
139
127
finally :
140
128
a .close ()
141
129
@@ -163,7 +151,6 @@ def configuration(parent_package='',top_path=None):
163
151
def setup_package ():
164
152
165
153
# Rewrite the version file everytime
166
- if os .path .exists ('numpy/version.py' ): os .remove ('numpy/version.py' )
167
154
write_version_py ()
168
155
169
156
# Perform 2to3 if needed
0 commit comments