Skip to content

Commit e08bed6

Browse files
committed
Improve the bump_versions script
1 parent 645f8e1 commit e08bed6

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

docs/Releasing.ipynb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"- TODO: create a `release.py` script\n",
2626
" [#88](https://github.com/krassowski/jupyterlab-lsp/issues/88)\n",
2727
"\n",
28+
"Use the `bump_versions` script to manage the version strings:\n",
29+
"\n",
30+
"```bash\n",
31+
"python scripts/bump_versions.py\n",
32+
"```\n",
33+
"\n",
2834
"The PyPI version (jupyter-lsp) must be updated in the following places:\n",
2935
"\n",
3036
"- `py_src/jupyter_lsp/_version.py` (canonical)\n",
@@ -87,4 +93,4 @@
8793
},
8894
"nbformat": 4,
8995
"nbformat_minor": 4
90-
}
96+
}

scripts/bump_versions.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env python3
22
"""Bump version of selected packages or core requirements (JupyterLab)"""
33
import sys
4+
from argparse import ArgumentParser
45
from dataclasses import dataclass
6+
from difflib import context_diff
57
from pathlib import Path
68
from typing import List
79

@@ -50,7 +52,13 @@ def maybe_change_version(self, dry: bool):
5052
def change_version(self, new_version: str, dry: bool):
5153

5254
changelog = CHANGELOG.read_text()
53-
assert new_version in changelog
55+
if new_version not in changelog:
56+
raise Exception(
57+
(
58+
f"{new_version} is absent in CHANGELOG.md file."
59+
f" Please update the changelog first."
60+
).format(new_version=new_version)
61+
)
5462

5563
for location in self.locations:
5664
replace_version(
@@ -63,12 +71,21 @@ def change_version(self, new_version: str, dry: bool):
6371

6472

6573
def replace_version(path: Path, template: str, old: str, new: str, dry: bool):
66-
new_content = path.read_text().replace(
74+
old_content = path.read_text()
75+
new_content = old_content.replace(
6776
template.format(version=old), template.format(version=new)
6877
)
6978
if dry:
70-
print(path)
71-
print(new_content)
79+
diff = context_diff(
80+
old_content.splitlines(),
81+
new_content.splitlines(),
82+
fromfile="current",
83+
tofile="new (proposed update)",
84+
n=4,
85+
)
86+
relative_path = path.relative_to(ROOT) if path.is_absolute() else path
87+
print("\n## Summary of changes proposed to {path}".format(path=relative_path))
88+
print("\n".join(diff) + "\n")
7289
else:
7390
path.write_text(new_content)
7491

@@ -127,4 +144,11 @@ def update_versions(dry: bool):
127144

128145

129146
if __name__ == "__main__":
130-
update_versions(dry=False)
147+
parser = ArgumentParser()
148+
parser.add_argument(
149+
"--dry",
150+
action="store_true",
151+
help="do not perform the update, only show the changes",
152+
)
153+
args = parser.parse_args()
154+
update_versions(dry=args.dry)

0 commit comments

Comments
 (0)