Use subprocess.check_output() instead of Popen().communicate()

This commit is contained in:
Aleksey Filippov 2018-03-11 23:24:34 +00:00
parent e4faf396e6
commit 093bdcafc9
1 changed files with 2 additions and 6 deletions

View File

@ -6,14 +6,10 @@ def generate(infile, outfile, fallback):
workdir = os.path.split(infile)[0] workdir = os.path.split(infile)[0]
if workdir == '': if workdir == '':
workdir = '.' workdir = '.'
version = fallback
try: try:
p = subprocess.Popen(['git', 'describe'], cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) version = subprocess.check_output(['git', 'describe'], cwd=workdir).decode().strip()
(stdo, _) = p.communicate()
if p.returncode == 0:
version = stdo.decode().strip()
except Exception: except Exception:
pass version = fallback
with open(infile) as f: with open(infile) as f:
newdata = f.read().replace('@VERSION@', version) newdata = f.read().replace('@VERSION@', version)
try: try: