Skip to content

Commit 645f8e1

Browse files
committed
Add bump version script
1 parent d8abdbe commit 645f8e1

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

scripts/bump_versions.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/env python3
2+
"""Bump version of selected packages or core requirements (JupyterLab)"""
3+
import sys
4+
from dataclasses import dataclass
5+
from pathlib import Path
6+
from typing import List
7+
8+
from integrity import CHANGELOG, PIPE_FILE as PIPELINE
9+
10+
ROOT = Path.cwd()
11+
12+
sys.path.insert(0, str(ROOT))
13+
14+
if True:
15+
# a workaround for isort 4.0 limitations
16+
# see https://github.com/timothycrosley/isort/issues/468
17+
from versions import ( # noqa
18+
JUPYTER_LSP_VERSION,
19+
JUPYTERLAB_LSP_VERSION,
20+
JUPYTERLAB_VERSION,
21+
REQUIRED_JUPYTERLAB,
22+
)
23+
24+
25+
META_PACKAGE = Path("packages/metapackage/package.json")
26+
JUPYTERLAB_LSP_PACKAGE = Path("packages/jupyterlab-lsp/package.json")
27+
README = Path("README.md")
28+
29+
NPM_PACKAGE_VERSION_TEMPLATE = '"version": "{version}"'
30+
31+
32+
@dataclass
33+
class VersionLocation:
34+
path: Path
35+
template: str
36+
37+
38+
@dataclass
39+
class PackageVersionInfo:
40+
name: str
41+
current_version: str
42+
locations: List[VersionLocation]
43+
44+
def maybe_change_version(self, dry: bool):
45+
print(f"Current {self.name} version is: {self.current_version}")
46+
version = input("Change it to [default=skip]: ").strip()
47+
if version:
48+
self.change_version(new_version=version, dry=dry)
49+
50+
def change_version(self, new_version: str, dry: bool):
51+
52+
changelog = CHANGELOG.read_text()
53+
assert new_version in changelog
54+
55+
for location in self.locations:
56+
replace_version(
57+
path=location.path,
58+
template=location.template,
59+
old=self.current_version,
60+
new=new_version,
61+
dry=dry,
62+
)
63+
64+
65+
def replace_version(path: Path, template: str, old: str, new: str, dry: bool):
66+
new_content = path.read_text().replace(
67+
template.format(version=old), template.format(version=new)
68+
)
69+
if dry:
70+
print(path)
71+
print(new_content)
72+
else:
73+
path.write_text(new_content)
74+
75+
76+
def update_versions(dry: bool):
77+
packages: List[PackageVersionInfo] = [
78+
PackageVersionInfo(
79+
name="jupyter-lsp (Python backend)",
80+
current_version=JUPYTER_LSP_VERSION,
81+
locations=[
82+
VersionLocation(
83+
path=Path("py_src/jupyter_lsp/_version.py"),
84+
template='__version__ = "{version}"',
85+
),
86+
VersionLocation(path=PIPELINE, template="PY_JLSP_VERSION: {version}"),
87+
],
88+
),
89+
PackageVersionInfo(
90+
name="jupyterlab-lsp (frontend package)",
91+
current_version=JUPYTERLAB_LSP_VERSION,
92+
locations=[
93+
VersionLocation(
94+
path=JUPYTERLAB_LSP_PACKAGE, template=NPM_PACKAGE_VERSION_TEMPLATE,
95+
),
96+
VersionLocation(path=PIPELINE, template="JS_JLLSP_VERSION: {version}"),
97+
VersionLocation(
98+
path=META_PACKAGE, template=NPM_PACKAGE_VERSION_TEMPLATE
99+
),
100+
],
101+
),
102+
PackageVersionInfo(
103+
name="JupyterLab - exact",
104+
current_version=JUPYTERLAB_VERSION,
105+
locations=[
106+
VersionLocation(
107+
path=JUPYTERLAB_LSP_PACKAGE,
108+
template='"@jupyterlab/application": "~{version}"',
109+
)
110+
],
111+
),
112+
PackageVersionInfo(
113+
name="JupyterLab - range",
114+
current_version=REQUIRED_JUPYTERLAB,
115+
locations=[
116+
VersionLocation(
117+
path=Path("binder/environment.yml"),
118+
template="jupyterlab {version}",
119+
),
120+
VersionLocation(path=README, template="jupyterlab {version}",),
121+
VersionLocation(path=README, template="JupyterLab {version}",),
122+
],
123+
),
124+
]
125+
for package in packages:
126+
package.maybe_change_version(dry=dry)
127+
128+
129+
if __name__ == "__main__":
130+
update_versions(dry=False)

0 commit comments

Comments
 (0)