Skip to content

Commit 626d2c7

Browse files
committed
MAINT: clean up the code of gitinfo function.
1 parent 661a3b7 commit 626d2c7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

site_scons/libdiffpybuildutils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@
44
'''
55

66
import os
7+
import re
78

89
MYDIR = os.path.dirname(os.path.abspath(__file__))
910

1011
def gitinfo():
1112
'Extract dictionary of version data from git records.'
12-
import re
1313
from subprocess import Popen, PIPE
1414
global _cached_gitinfo
15-
if _cached_gitinfo is not None: return _cached_gitinfo
16-
rv = _cached_gitinfo = {}
15+
if _cached_gitinfo is not None:
16+
return _cached_gitinfo
1717
nullfile = open(os.devnull, 'w')
1818
kw = dict(stdout=PIPE, stderr=nullfile, cwd=MYDIR)
1919
proc = Popen(['git', 'describe', '--match=v[[:digit:]]*'], **kw)
2020
desc = proc.stdout.read()
21-
if proc.wait(): return gitinfo()
21+
if proc.wait():
22+
_cached_gitinfo = {}
23+
return gitinfo()
2224
proc = Popen(['git', 'log', '-1', '--format=%H %ai'], **kw)
2325
glog = proc.stdout.read()
2426
words = desc.strip().split('-')
2527
vtag = words[0].lstrip('v')
2628
vnum = int((words[1:2] or ['0'])[0])
29+
rv = {}
2730
rv['commit'], rv['date'] = glog.strip().split(None, 1)
2831
mx = re.match(r'^(\d+)\.(\d+)(?:\.(\d+))?((?:[ab]|rc)\d*)?', vtag)
2932
rv['major'] = int(mx.group(1))

0 commit comments

Comments
 (0)