Skip to content

Commit fe9c0ae

Browse files
author
y-p
committed
BLD: Handle git describe failure more cleanly in setup.py GH5495
1 parent cfcade2 commit fe9c0ae

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

setup.py

+22-18
Original file line numberDiff line numberDiff line change
@@ -197,26 +197,30 @@ def build_extensions(self):
197197

198198
FULLVERSION = VERSION
199199
if not ISRELEASED:
200+
import subprocess
200201
FULLVERSION += '.dev'
201-
try:
202-
import subprocess
202+
203+
for cmd in ['git','git.cmd']:
203204
try:
204-
pipe = subprocess.Popen(["git", "describe", "--always"],
205-
stdout=subprocess.PIPE).stdout
206-
except OSError:
207-
# msysgit compatibility
208-
pipe = subprocess.Popen(
209-
["git.cmd", "describe", "--always"],
210-
stdout=subprocess.PIPE).stdout
211-
rev = pipe.read().strip()
212-
# makes distutils blow up on Python 2.7
213-
if sys.version_info[0] >= 3:
214-
rev = rev.decode('ascii')
215-
216-
FULLVERSION = rev.lstrip('v')
217-
218-
except:
219-
warnings.warn("WARNING: Couldn't get git revision")
205+
pipe = subprocess.Popen([cmd, "describe", "--always"],
206+
stdout=subprocess.PIPE)
207+
(so,serr) = pipe.communicate()
208+
if pipe.returncode == 0:
209+
break
210+
except:
211+
pass
212+
213+
if pipe.returncode != 0:
214+
warnings.warn("WARNING: Couldn't get git revision, using generic version string")
215+
else:
216+
rev = so.strip()
217+
# makes distutils blow up on Python 2.7
218+
if sys.version_info[0] >= 3:
219+
rev = rev.decode('ascii')
220+
221+
# use result og git describe as version string
222+
FULLVERSION = rev.lstrip('v')
223+
220224
else:
221225
FULLVERSION += QUALIFIER
222226

0 commit comments

Comments
 (0)