Skip to content
Browse files

ENH: Add Git revision hash to numpy dev version string

- Appends the first 6 characters of the Git revision used to build
  Numpy

- Adds an additional attribute to easily obtain the full Git revision
  • Loading branch information...
1 parent 8adfc76 commit 58e63603e6eef1e3710a0ddae938b25ffb7c3bce @scottza scottza committed with charris Nov 9, 2010
Showing with 27 additions and 39 deletions.
  1. +1 −0 numpy/__init__.py
  2. +26 −39 setup.py
View
1 numpy/__init__.py
@@ -125,6 +125,7 @@
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there."""
raise ImportError(msg)
+ from version import git_revision as __git_revision__
from version import version as __version__
from _import_tools import PackageLoader
View
65 setup.py
@@ -59,8 +59,8 @@
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
-# Return the svn version as a string, raise a ValueError otherwise
-def svn_version():
+# Return the git revision as a string
+def git_version():
def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
@@ -76,25 +76,12 @@ def _minimal_ext_cmd(cmd):
return out
try:
- out = _minimal_ext_cmd(['svn', 'info'])
+ out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
+ GIT_REVISION = out.strip()
except OSError:
- print(" --- Could not run svn info --- ")
- return ""
+ GIT_REVISION = "Unknwn"
- r = re.compile('Revision: ([0-9]+)')
- svnver = ""
-
- out = out.decode()
-
- for line in out.split('\n'):
- m = r.match(line.strip())
- if m:
- svnver = m.group(1)
-
- if not svnver:
- print("Error while parsing svn version")
-
- return svnver
+ return GIT_REVISION
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
# update it when the contents of directories change.
@@ -106,36 +93,37 @@ def _minimal_ext_cmd(cmd):
# a lot more robust than what was previously being used.
builtins.__NUMPY_SETUP__ = True
-FULLVERSION = VERSION
-if not ISRELEASED:
- FULLVERSION += '.dev'
- # If in git or something, bypass the svn rev
- if os.path.exists('.svn'):
- FULLVERSION += svn_version()
-
def write_version_py(filename='numpy/version.py'):
cnt = """
# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
short_version='%(version)s'
version='%(version)s'
+full_version='%(full_version)s'
+git_revision='%(git_revision)s'
release=%(isrelease)s
if not release:
- version += '.dev'
- import os
- svn_version_file = os.path.join(os.path.dirname(__file__),
- 'core','__svn_version__.py')
- if os.path.isfile(svn_version_file):
- import imp
- svn = imp.load_module('numpy.core.__svn_version__',
- open(svn_version_file),
- svn_version_file,
- ('.py','U',1))
- version += svn.version
+ version = full_version
"""
+ FULL_VERSION = VERSION
+ if not ISRELEASED:
+ FULL_VERSION += '.dev'
+ if os.path.exists('.git'):
+ GIT_REVISION = git_version()
+ elif os.path.exists(filename):
+ # must be a source distribution, use existing version file
+ from numpy.version import git_revision as GIT_REVISION
+ else:
+ GIT_REVISION = "Unknwn"
+
+ FULL_VERSION += GIT_REVISION[:6]
+
a = open(filename, 'w')
try:
- a.write(cnt % {'version': VERSION, 'isrelease': str(ISRELEASED)})
+ a.write(cnt % {'version': VERSION,
+ 'full_version' : FULL_VERSION,
+ 'git_revision' : GIT_REVISION,
+ 'isrelease': str(ISRELEASED)})
finally:
a.close()
@@ -163,7 +151,6 @@ def configuration(parent_package='',top_path=None):
def setup_package():
# Rewrite the version file everytime
- if os.path.exists('numpy/version.py'): os.remove('numpy/version.py')
write_version_py()
# Perform 2to3 if needed

0 comments on commit 58e6360

Please sign in to comment.
Something went wrong with that request. Please try again.