Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ENH: Add Git revision hint to version information for dev versions

  • Loading branch information...
commit 74dccec7b8e8cbf056d2d7383f26619c63acd0e7 1 parent 831ab95
@scottza scottza authored rgommers committed
Showing with 72 additions and 57 deletions.
  1. +61 −53 setup.py
  2. +11 −4 setupscons.py
View
114 setup.py
@@ -48,69 +48,77 @@
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
-# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
-# update it when the contents of directories change.
-if os.path.exists('MANIFEST'): os.remove('MANIFEST')
-
-os.environ['NO_SCIPY_IMPORT']='SciPy/setup.py'
-# Return the svn version as a string, raise a ValueError otherwise
-def svn_version():
- from numpy.compat import asstr
+# Return the git revision as a string
+def git_version():
+ def _minimal_ext_cmd(cmd):
+ # construct minimal environment
+ env = {}
+ for k in ['SYSTEMROOT', 'PATH']:
+ v = os.environ.get(k)
+ if v is not None:
+ env[k] = v
+ # LANGUAGE is used on win32
+ env['LANGUAGE'] = 'C'
+ env['LANG'] = 'C'
+ env['LC_ALL'] = 'C'
+ out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0]
+ return out
- env = os.environ.copy()
- env['LC_ALL'] = 'C'
try:
- out = subprocess.Popen(['svn', 'info'], stdout=subprocess.PIPE,
- env=env).communicate()[0]
+ out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
+ GIT_REVISION = out.strip().decode('ascii')
except OSError:
- warnings.warn(" --- Could not run svn info --- ")
- return ""
-
- r = re.compile('Revision: ([0-9]+)')
- svnver = None
- for line in asstr(out).split('\n'):
- m = r.match(line)
- if m:
- svnver = m.group(1)
-
- if not svnver:
- raise ValueError("Error while parsing svn version ?")
- return svnver
-
-FULLVERSION = VERSION
-if not ISRELEASED:
- FULLVERSION += '.dev'
- # If in git or something, bypass the svn rev
- if os.path.exists('.svn'):
- FULLVERSION += svn_version()
+ GIT_REVISION = "Unknown"
+
+ return GIT_REVISION
+
+
+# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
+# update it when the contents of directories change.
+if os.path.exists('MANIFEST'):
+ os.remove('MANIFEST')
+
+os.environ['NO_SCIPY_IMPORT'] = 'SciPy/setup.py'
+
def write_version_py(filename='scipy/version.py'):
- cnt = """\
+ cnt = """
# THIS FILE IS GENERATED FROM SCIPY SETUP.PY
-short_version='%(version)s'
-version='%(version)s'
-release=%(isrelease)s
+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__),
- '__svn_version__.py')
- if os.path.isfile(svn_version_file):
- import imp
- svn = imp.load_module('scipy.__svn_version__',
- open(svn_version_file),
- svn_version_file,
- ('.py','U',1))
- version += svn.version
+ version = full_version
"""
+ # Adding the git rev number needs to be done inside
+ # write_version_py(), otherwise the import of scipy.version messes
+ # up the build under Python 3.
+ FULLVERSION = VERSION
+ if os.path.exists('.git'):
+ GIT_REVISION = git_version()
+ elif os.path.exists('scipy/version.py'):
+ # must be a source distribution, use existing version file
+ from scipy.version import git_revision as GIT_REVISION
+ else:
+ GIT_REVISION = "Unknown"
+
+ if not ISRELEASED:
+ FULLVERSION += '.dev-' + GIT_REVISION[:7]
+
a = open(filename, 'w')
try:
- a.write(cnt % {'version': VERSION, 'isrelease': str(ISRELEASED)})
+ a.write(cnt % {'version': VERSION,
+ 'full_version' : FULLVERSION,
+ 'git_revision' : GIT_REVISION,
+ 'isrelease': str(ISRELEASED)})
finally:
a.close()
+
def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration(None, parent_package, top_path)
@@ -126,10 +134,9 @@ def configuration(parent_package='',top_path=None):
return config
-def setup_package():
+def setup_package():
from numpy.distutils.core import setup
- from numpy.distutils.misc_util import Configuration
old_path = os.getcwd()
local_path = os.path.dirname(os.path.abspath(sys.argv[0]))
@@ -146,8 +153,8 @@ def setup_package():
shutil.copy(site_cfg, src_path)
os.chdir(local_path)
- sys.path.insert(0,local_path)
- sys.path.insert(0,os.path.join(local_path,'scipy')) # to retrive version
+ sys.path.insert(0, local_path)
+ sys.path.insert(0, os.path.join(local_path, 'scipy')) # to retrieve version
# Run build
old_path = os.getcwd()
@@ -155,7 +162,6 @@ def setup_package():
sys.path.insert(0, src_path)
# Rewrite the version file everytime
- if os.path.exists('scipy/version.py'): os.remove('scipy/version.py')
write_version_py()
try:
@@ -177,5 +183,7 @@ def setup_package():
return
+
if __name__ == '__main__':
setup_package()
+
View
15 setupscons.py
@@ -21,6 +21,7 @@
import os
import sys
+
CLASSIFIERS = """\
Development Status :: 4 - Beta
Intended Audience :: Science/Research
@@ -37,20 +38,22 @@
"""
+
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
# update it when the contents of directories change.
-if os.path.exists('MANIFEST'): os.remove('MANIFEST')
+if os.path.exists('MANIFEST'):
+ os.remove('MANIFEST')
-os.environ['NO_SCIPY_IMPORT']='SciPy/setup.py'
+os.environ['NO_SCIPY_IMPORT'] = 'SciPy/setup.py'
sys.path.insert(0, os.path.dirname(__file__))
try:
setup_py = __import__("setup")
- FULLVERSION = setup_py.FULLVERSION
write_version_py = setup_py.write_version_py
finally:
sys.path.pop(0)
+
def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration(None, parent_package, top_path, setup_name = "setupscons.py")
@@ -66,6 +69,7 @@ def configuration(parent_package='',top_path=None):
return config
+
def setup_package():
from numpy.distutils.core import setup
@@ -78,7 +82,9 @@ def setup_package():
sys.path.insert(0,os.path.join(local_path,'scipy')) # to retrive version
# Rewrite the version file everytime
- if os.path.exists('scipy/version.py'): os.remove('scipy/version.py')
+ if os.path.exists('scipy/version.py'):
+ os.remove('scipy/version.py')
+
write_version_py()
try:
@@ -100,5 +106,6 @@ def setup_package():
return
+
if __name__ == '__main__':
setup_package()
Please sign in to comment.
Something went wrong with that request. Please try again.