From 64f5067db70b4e56258fc80d4fbc9c21a257c73b Mon Sep 17 00:00:00 2001 From: Daniel Wheeler Date: Fri, 31 Aug 2012 10:27:29 -0400 Subject: [PATCH] SvnToGit cleanup -- ticket:461 -- fipy version obtained with git The version number is formatted as ``3.0-dev1-gd76b767`` or as ``3.0`` where the number after dev refers to the number of commits since that version. * getVersion() uses ``git describe --tags --match version-*`` * if git is unavailable ``getVersion()`` uses ``_getVersion()`` in ``fipy/__init__.py``, which uses ``FiPy.egg-info``. The ``egg-info`` directory is part of the distribution. * Tested with tarred distributions. --- setup.py | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/setup.py b/setup.py index 52e8c38209..91f5cebbb7 100644 --- a/setup.py +++ b/setup.py @@ -217,7 +217,7 @@ def run(self): # }, ##Hacked from numpy -def svn_version(): +def getVersion(): def _minimal_ext_cmd(cmd): # construct minimal environment env = {} @@ -233,35 +233,23 @@ def _minimal_ext_cmd(cmd): out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0] return out - try: - out = _minimal_ext_cmd(['svn', 'info']) - except OSError: - print(" --- Could not run svn info --- ") - return "" + version = 'unknown' - import re - r = re.compile('Revision: ([0-9]+)') - svnver = "" - - out = str(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 + if os.path.exists('.git'): + try: + out = _minimal_ext_cmd(['git', 'describe', '--tags', '--match', 'version-*']) + version = out.strip().replace('version-', '').replace('_', '.').replace('-', '-dev', 1) + except OSError: + import warnings + warnings.warn("Could not run ``git describe``") + elif os.path.exists('FiPy.egg-info'): + from fipy import _getVersion + version = _getVersion() -def getVersion(version, release=False): - if not release: - version += '-dev' + svn_version() return version dist = setup( name = "FiPy", - version = getVersion(version='3.0', release=False), + version = getVersion(), author = "Jonathan Guyer, Daniel Wheeler, & Jim Warren", author_email = "fipy@nist.gov", url = "http://www.ctcms.nist.gov/fipy/",