|
1 | 1 | # Copyright (c) Jupyter Development Team.
|
2 | 2 | # Distributed under the terms of the Modified BSD License.
|
3 | 3 |
|
4 |
| -import json |
| 4 | +import argparse |
| 5 | +from packaging.version import parse as parse_version |
5 | 6 | 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 |
11 | 8 |
|
12 | 9 | LERNA_CMD = "yarn run lerna version --no-push --force-publish --no-git-tag-version"
|
13 | 10 |
|
14 | 11 |
|
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 |
50 | 44 | lerna_cmd = f"{LERNA_CMD} {js_version}"
|
51 |
| - if force: |
| 45 | + if args.force: |
52 | 46 | lerna_cmd += " --yes"
|
53 |
| - run(lerna_cmd) |
54 | 47 |
|
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) |
60 | 56 |
|
61 |
| - data["version"] = js_version |
| 57 | + # data["version"] = js_version |
62 | 58 |
|
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) |
65 | 61 |
|
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}") |
68 | 64 |
|
69 | 65 |
|
70 | 66 | if __name__ == "__main__":
|
|
0 commit comments