From fe9c0ae0b703ce6a7164ceaa309ddb3cfda54394 Mon Sep 17 00:00:00 2001 From: y-p Date: Thu, 19 Dec 2013 06:55:07 +0200 Subject: [PATCH] BLD: Handle git describe failure more cleanly in setup.py GH5495 --- setup.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) 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