Skip to content

Commit 31be207

Browse files
committed
preprocess_frozen_modules.py: yet more Python 3.4 compatibility changes
1 parent 644ad74 commit 31be207

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tools/preprocess_frozen_modules.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
import semver
77
import subprocess
88

9+
# Compatible with Python 3.4 due to travis using trusty as default.
10+
911
def version_string(path=None, *, valid_semver=False):
1012
version = None
11-
tag = subprocess.run('git describe --tags --exact-match', shell=True,
12-
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=path)
13-
if tag.returncode == 0:
14-
version = tag.stdout.strip().decode("utf-8", "strict")
15-
else:
16-
describe = subprocess.run("git describe --tags", shell=True, stdout=subprocess.PIPE, cwd=path)
17-
tag, additional_commits, commitish = describe.stdout.strip().decode("utf-8", "strict").rsplit("-", maxsplit=2)
13+
try:
14+
tag = subprocess.check_output('git describe --tags --exact-match', shell=True, cwd=path)
15+
version = tag.strip().decode("utf-8", "strict")
16+
except subprocess.CalledProcessError:
17+
describe = subprocess.check_output("git describe --tags", shell=True, cwd=path)
18+
tag, additional_commits, commitish = describe.strip().decode("utf-8", "strict").rsplit("-", maxsplit=2)
1819
commitish = commitish[1:]
1920
if valid_semver:
2021
version_info = semver.parse_version_info(tag)
@@ -45,7 +46,6 @@ def copy_and_process(in_dir, out_dir):
4546
output_file_path = Path(out_dir, input_file_path.relative_to(in_dir))
4647

4748
if file.endswith(".py"):
48-
# mkdir() takes an exists_ok=True, but not until Python 3.5.
4949
if not output_file_path.parent.exists():
5050
output_file_path.parent.mkdir(parents=True)
5151
with input_file_path.open("r") as input, output_file_path.open("w") as output:

0 commit comments

Comments
 (0)