Skip to content

Commit ad0d3df

Browse files
committed
restore bump version script
1 parent a858e27 commit ad0d3df

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@ source_dir = "src"
7171
build_dir = "jupyterlab_blockly/labextension"
7272

7373
[tool.jupyter-releaser.options]
74-
version_cmd = "hatch version"
74+
version_cmd = "python scripts/bump-version.py --force"
7575

7676
[tool.jupyter-releaser.hooks]
77+
before-bump-version = [
78+
"python -m pip install 'jupyterlab>=4.0.0,<5'",
79+
"jlpm"
80+
]
7781
before-build-npm = [
7882
"python -m pip install 'jupyterlab>=4.0.0,<5'",
7983
"jlpm",

scripts/bump-version.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#############################################################################
2+
# Copyright (c) 2018, Voila Contributors #
3+
# Copyright (c) 2024, QuantStack #
4+
# #
5+
# Distributed under the terms of the BSD 3-Clause License. #
6+
# #
7+
# The full license is in the file LICENSE, distributed with this software. #
8+
#############################################################################
9+
10+
import json
11+
from pathlib import Path
12+
13+
import click
14+
from jupyter_releaser.util import get_version, run
15+
from pkg_resources import parse_version
16+
17+
LERNA_CMD = "jlpm lerna version --no-push --force-publish --no-git-tag-version"
18+
19+
20+
@click.command()
21+
@click.option("--force", default=False, is_flag=True)
22+
@click.argument("spec", nargs=1)
23+
def bump(force, spec):
24+
status = run("git status --porcelain").strip()
25+
if len(status) > 0:
26+
raise Exception("Must be in a clean git state with no untracked files")
27+
28+
curr = parse_version(get_version())
29+
if spec == 'next':
30+
spec = f"{curr.major}.{curr.minor}."
31+
if curr.pre:
32+
p, x = curr.pre
33+
spec += f"{curr.micro}{p}{x + 1}"
34+
else:
35+
spec += f"{curr.micro + 1}"
36+
37+
elif spec == 'patch':
38+
spec = f"{curr.major}.{curr.minor}."
39+
if curr.pre:
40+
spec += f"{curr.micro}"
41+
else:
42+
spec += f"{curr.micro + 1}"
43+
44+
45+
version = parse_version(spec)
46+
47+
# convert the Python version
48+
js_version = f"{version.major}.{version.minor}.{version.micro}"
49+
if version.pre:
50+
p, x = version.pre
51+
p = p.replace("a", "alpha").replace("b", "beta")
52+
js_version += f"-{p}.{x}"
53+
54+
# bump the JS packages
55+
lerna_cmd = f"{LERNA_CMD} {js_version}"
56+
if force:
57+
lerna_cmd += " --yes"
58+
run(lerna_cmd)
59+
60+
HERE = Path(__file__).parent.parent.resolve()
61+
path = HERE.joinpath("package.json")
62+
if path.exists():
63+
with path.open(mode="r") as f:
64+
data = json.load(f)
65+
66+
data["version"] = js_version
67+
68+
with path.open(mode="w") as f:
69+
json.dump(data, f, indent=2)
70+
71+
else:
72+
raise FileNotFoundError(f"Could not find package.json under dir {path!s}")
73+
74+
75+
if __name__ == "__main__":
76+
bump()

0 commit comments

Comments
 (0)