Skip to content

Commit f0f07c6

Browse files
committed
Build: report Git errors; handle shallow clones in 'git describe'
1 parent 9dc7e7a commit f0f07c6

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

setup.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@
4949
ISRELEASED = True
5050
# assume a version set by conda, next update with git,
5151
# otherwise count on default
52-
VERSION = 'Unkown'
52+
VERSION = 'Unknown'
53+
54+
class GitError(RuntimeError):
55+
"""Exception for git errors occuring in in git_version"""
56+
pass
5357

5458
# Return the git version, revision and cycle
5559
#
@@ -68,11 +72,17 @@ def _minimal_ext_cmd(cmd, srcdir):
6872
env['LANGUAGE'] = 'C'
6973
env['LANG'] = 'C'
7074
env['LC_ALL'] = 'C'
71-
out = subprocess.Popen(
75+
proc = subprocess.Popen(
7276
cmd,
7377
cwd=srcdir,
7478
stdout=subprocess.PIPE,
75-
env=env).communicate()[0]
79+
stderr=subprocess.PIPE,
80+
env=env)
81+
out, err = proc.communicate()
82+
if proc.returncode:
83+
errmsg = err.decode('ascii',errors='ignore').strip()
84+
raise GitError("git err; return code %d, error message:\n '%s'"
85+
% (proc.returncode, errmsg))
7686
return out
7787

7888
try:
@@ -83,8 +93,12 @@ def _minimal_ext_cmd(cmd, srcdir):
8393
GIT_REVISION = out.strip().decode('ascii')
8494
out = _minimal_ext_cmd(['git', 'tag'], srcdir)
8595
GIT_VERSION = out.strip().decode('ascii').split('\n')[-1][1:]
86-
out = _minimal_ext_cmd(['git', 'describe', '--tags', '--long'], srcdir)
87-
GIT_CYCLE = out.strip().decode('ascii').split('-')[1]
96+
out = _minimal_ext_cmd(['git', 'describe', '--tags', '--long','--always'], srcdir)
97+
try:
98+
# don't get a good description with shallow clones, e.g., on Travis
99+
GIT_CYCLE = out.strip().decode('ascii').split('-')[1]
100+
except IndexError:
101+
pass
88102
except OSError:
89103
pass
90104

0 commit comments

Comments
 (0)