Skip to content

Commit 38cc106

Browse files
committed
Fix parsing of current version
1 parent 09419bd commit 38cc106

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

scripts/commit_version.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def main(argv):
1313
source_dir = argv[1]
1414
version = argv[2]
1515
history_path = os.path.join(PROJECT_DIRECTORY, "HISTORY.rst")
16-
with open(history_path, "r") as f:
16+
with open(history_path) as f:
1717
history = f.read()
1818
today = datetime.datetime.today()
1919
today_str = today.strftime("%Y-%m-%d")
@@ -22,21 +22,12 @@ def main(argv):
2222
f.write(history)
2323

2424
source_mod_path = os.path.join(PROJECT_DIRECTORY, source_dir, "__init__.py")
25-
with open(source_mod_path, "r") as f:
25+
with open(source_mod_path) as f:
2626
mod = f.read()
27-
mod = re.sub("__version__ = '[\d\.]*\.dev0'", "__version__ = '%s'" % version, mod)
27+
mod = re.sub(r'__version__ = "[\d\.]*\.dev0"', f'__version__ = "{version}"', mod)
2828
with open(source_mod_path, "w") as f:
2929
mod = f.write(mod)
30-
shell(
31-
[
32-
"git",
33-
"commit",
34-
"-m",
35-
"Version %s" % version,
36-
"HISTORY.rst",
37-
"%s/__init__.py" % source_dir,
38-
]
39-
)
30+
shell(["git", "commit", "-m", f"Version {version}", "HISTORY.rst", f"{source_dir}/__init__.py"])
4031
shell(["git", "tag", version])
4132

4233

scripts/new_version.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def main(argv):
2828
new_version = ".".join(map(str, new_version_tuple))
2929

3030
history_path = os.path.join(PROJECT_DIRECTORY, "HISTORY.rst")
31-
with open(history_path, "r") as f:
31+
with open(history_path) as f:
3232
history = f.read()
3333

3434
def extend(from_str, line):
@@ -48,21 +48,12 @@ def extend(from_str, line):
4848
f.write(history)
4949

5050
source_mod_path = os.path.join(PROJECT_DIRECTORY, source_dir, "__init__.py")
51-
with open(source_mod_path, "r") as f:
51+
with open(source_mod_path) as f:
5252
mod = f.read()
53-
mod = re.sub(r"__version__ = '[\d\.]+'", "__version__ = '%s.dev0'" % new_version, mod, 1)
53+
mod = re.sub(r'__version__ = "[\d\.]+"', f"__version__ = '{new_version}.dev0'", mod, 1)
5454
with open(source_mod_path, "w") as f:
5555
mod = f.write(mod)
56-
shell(
57-
[
58-
"git",
59-
"commit",
60-
"-m",
61-
"Starting work on %s" % new_version,
62-
"HISTORY.rst",
63-
"%s/__init__.py" % source_dir,
64-
]
65-
)
56+
shell(["git", "commit", "-m", f"Starting work on {new_version}", "HISTORY.rst", f"{source_dir}/__init__.py"])
6657

6758

6859
def shell(cmds, **kwds):

scripts/print_version_for_release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
_version_re = re.compile(r"__version__\s+=\s+(.*)")
1212

13-
with open("%s/__init__.py" % source_dir, "rb") as f:
14-
version = str(ast.literal_eval(_version_re.search(f.read().decode("utf-8")).group(1)))
13+
with open(f"{source_dir}/__init__.py") as f:
14+
version = str(ast.literal_eval(_version_re.search(f.read()).group(1)))
1515

1616
version_obj = Version(version)
1717
# Strip .devN

0 commit comments

Comments
 (0)