Skip to content

Commit 1d655c9

Browse files
authored
Fix bump_version.py (#66)
* Fix bump_version.py * Fix args.spec * Import missing which * Remove which * Add Python dev tool for handling version
1 parent 8661726 commit 1d655c9

File tree

2 files changed

+55
-53
lines changed

2 files changed

+55
-53
lines changed

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ dependencies = [
2525
]
2626
dynamic = ["version", "description", "authors", "urls", "keywords"]
2727

28+
[project.optional-dependencies]
29+
dev = [
30+
"hatch>=1.5.0",
31+
"jupyterlab"
32+
]
33+
2834
[tool.hatch.version]
2935
source = "nodejs"
3036

scripts/bump_version.py

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,66 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4-
import json
4+
import argparse
5+
from packaging.version import parse as parse_version
56
from pathlib import Path
6-
from shutil import which
7-
8-
import click
9-
from jupyter_releaser.util import get_version, run
10-
from pkg_resources import parse_version # type: ignore
7+
from subprocess import run
118

129
LERNA_CMD = "yarn run lerna version --no-push --force-publish --no-git-tag-version"
1310

1411

15-
@click.command()
16-
@click.option("--force", default=False, is_flag=True)
17-
@click.argument("spec", nargs=1)
18-
def bump(force, spec):
19-
status = run("git status --porcelain").strip()
20-
if len(status) > 0:
21-
raise Exception("Must be in a clean git state with no untracked files")
22-
23-
curr = parse_version(get_version())
24-
if spec == "next":
25-
spec = f"{curr.major}.{curr.minor}."
26-
if curr.pre:
27-
p, x = curr.pre
28-
spec += f"{curr.micro}{p}{x + 1}"
29-
else:
30-
spec += f"{curr.micro + 1}"
31-
32-
elif spec == "patch":
33-
spec = f"{curr.major}.{curr.minor}."
34-
if curr.pre:
35-
spec += f"{curr.micro}"
36-
else:
37-
spec += f"{curr.micro + 1}"
38-
39-
version = parse_version(spec)
40-
41-
# convert the Python version
42-
js_version = f"{version.major}.{version.minor}.{version.micro}"
43-
if version.pre:
44-
p, x = version.pre
45-
p = p.replace("a", "alpha").replace("b", "beta")
46-
js_version += f"-{p}.{x}"
47-
48-
# bump the JS packages
49-
run(f"{which('yarn')} install")
12+
ENC = dict(encoding="utf-8")
13+
HATCH_VERSION = "hatch version"
14+
ROOT = Path(__file__).parent.parent
15+
16+
17+
def get_version():
18+
cmd = run([HATCH_VERSION], capture_output=True, shell=True, check=True, cwd=ROOT)
19+
return cmd.stdout.decode("utf-8").strip().split("\n")[-1]
20+
21+
22+
def next_version():
23+
v = parse_version(get_version())
24+
if v.is_prerelease:
25+
return f"{v.major}.{v.minor}.{v.micro}{v.pre[0]}{v.pre[1] + 1}"
26+
return f"{v.major}.{v.minor}.{v.micro + 1}"
27+
28+
29+
def bump():
30+
parser = argparse.ArgumentParser()
31+
parser.add_argument("spec")
32+
parser.add_argument("--force", action='store_true')
33+
args = parser.parse_args()
34+
py_version = next_version() if args.spec == "next" else args.spec
35+
36+
# bump the Python version with hatch
37+
run(f"{HATCH_VERSION} {py_version}", shell=True, check=True, cwd=ROOT)
38+
39+
js_version = (
40+
get_version().replace("a", "-alpha.").replace("b", "-beta.").replace("rc", "-rc.")
41+
)
42+
43+
# bump the JS version with lerna
5044
lerna_cmd = f"{LERNA_CMD} {js_version}"
51-
if force:
45+
if args.force:
5246
lerna_cmd += " --yes"
53-
run(lerna_cmd)
5447

55-
HERE = Path(__file__).parent.parent.resolve()
56-
path = HERE.joinpath("package.json")
57-
if path.exists():
58-
with path.open(mode="r") as f:
59-
data = json.load(f)
48+
run("yarn install", shell=True, check=True, cwd=ROOT)
49+
run(lerna_cmd, shell=True, check=True, cwd=ROOT)
50+
51+
# HERE = Path(__file__).parent.parent.resolve()
52+
# path = HERE.joinpath("package.json")
53+
# if path.exists():
54+
# with path.open(mode="r") as f:
55+
# data = json.load(f)
6056

61-
data["version"] = js_version
57+
# data["version"] = js_version
6258

63-
with path.open(mode="w") as f:
64-
json.dump(data, f, indent=2)
59+
# with path.open(mode="w") as f:
60+
# json.dump(data, f, indent=2)
6561

66-
else:
67-
raise FileNotFoundError(f"Could not find package.json under dir {path!s}")
62+
# else:
63+
# raise FileNotFoundError(f"Could not find package.json under dir {path!s}")
6864

6965

7066
if __name__ == "__main__":

0 commit comments

Comments
 (0)