diff --git a/setup.py b/setup.py index fe921b1ff6029..5a09a27f36eee 100755 --- a/setup.py +++ b/setup.py @@ -197,26 +197,30 @@ def build_extensions(self): FULLVERSION = VERSION if not ISRELEASED: + import subprocess FULLVERSION += '.dev' - try: - import subprocess + + for cmd in ['git','git.cmd']: try: - pipe = subprocess.Popen(["git", "describe", "--always"], - stdout=subprocess.PIPE).stdout - except OSError: - # msysgit compatibility - pipe = subprocess.Popen( - ["git.cmd", "describe", "--always"], - stdout=subprocess.PIPE).stdout - rev = pipe.read().strip() - # makes distutils blow up on Python 2.7 - if sys.version_info[0] >= 3: - rev = rev.decode('ascii') - - FULLVERSION = rev.lstrip('v') - - except: - warnings.warn("WARNING: Couldn't get git revision") + pipe = subprocess.Popen([cmd, "describe", "--always"], + stdout=subprocess.PIPE) + (so,serr) = pipe.communicate() + if pipe.returncode == 0: + break + except: + pass + + if pipe.returncode != 0: + warnings.warn("WARNING: Couldn't get git revision, using generic version string") + else: + rev = so.strip() + # makes distutils blow up on Python 2.7 + if sys.version_info[0] >= 3: + rev = rev.decode('ascii') + + # use result og git describe as version string + FULLVERSION = rev.lstrip('v') + else: FULLVERSION += QUALIFIER