@@ -17,16 +17,27 @@ def _minimal_ext_cmd(cmd):
17
17
env ['LANGUAGE' ] = 'C'
18
18
env ['LANG' ] = 'C'
19
19
env ['LC_ALL' ] = 'C'
20
- out = subprocess .Popen (cmd , stdout = subprocess .PIPE , env = env ).communicate ()[0 ]
20
+ out = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = open ( '/dev/null' , 'w' ) , env = env ).communicate ()[0 ]
21
21
return out
22
22
23
23
import os , subprocess
24
24
base , _ = os .path .split (__file__ )
25
25
26
26
tag = "<<unknown>>"
27
27
try :
28
- cmd = ['git' , '--work-tree' , '%s/../..' % base , 'describe' , '--long' , '--abbrev=8' ]
28
+ # Have to call 'git status' first, because of a git bug where it incorrectly detects
29
+ # a tree as dirty under conditions triggered by things like './setup.py sdist'
30
+ cmd = ['git' , '--work-tree' , '%s/../..' % base , 'status' ]
31
+ _minimal_ext_cmd (cmd )
32
+
33
+ # Try with the --dirty flag (newer versions of git support this)
34
+ cmd = ['git' , '--work-tree' , '%s/../..' % base , 'describe' , '--long' , '--abbrev=8' , '--dirty' ]
29
35
tag = _minimal_ext_cmd (cmd )
36
+
37
+ if tag == "" :
38
+ # Try without the --dirty flag (for older versions of git)
39
+ cmd = ['git' , '--work-tree' , '%s/../..' % base , 'describe' , '--long' , '--abbrev=8' ]
40
+ tag = _minimal_ext_cmd (cmd )
30
41
except OSError :
31
42
pass
32
43
@@ -36,17 +47,19 @@ def _minimal_ext_cmd(cmd):
36
47
if tag [:1 ] == 'v' :
37
48
tag = tag [1 :]
38
49
# Parse the tag into components
39
- (version , additional_commits , hash ) = tag .split ('-' )
50
+ tagparts = tag .split ('-' )
51
+ (version , additional_commits , hash ) = tagparts [:3 ]
52
+ dirty = len (tagparts ) > 3
40
53
ver_tuple = tuple ( int (v ) for v in version .split ('.' ) )
41
54
additional_commits = int (additional_commits )
42
55
hash = hash [1 :]
43
56
44
- if additional_commits == 0 :
57
+ if additional_commits == 0 and not dirty :
45
58
__version__ = version
46
59
else :
47
60
__version__ = tag
48
61
49
- __version_info__ = (ver_tuple , additional_commits , hash )
62
+ __version_info__ = (ver_tuple , additional_commits , hash , dirty )
50
63
else :
51
64
__version__ = tag
52
- __version_info__ = ((99 , 99 , 99 ), 99 , '0' * 8 )
65
+ __version_info__ = ((99 , 99 , 99 ), 99 , '0' * 8 , True )
0 commit comments