-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from QuantStack/bumpVersion
Restore `bump-version` script
- Loading branch information
Showing
2 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
############################################################################# | ||
# Copyright (c) 2024, Voila Contributors # | ||
# Copyright (c) 2024, QuantStack # | ||
# # | ||
# Distributed under the terms of the BSD 3-Clause License. # | ||
# # | ||
# The full license is in the file LICENSE, distributed with this software. # | ||
############################################################################# | ||
|
||
import json | ||
from pathlib import Path | ||
|
||
import click | ||
from jupyter_releaser.util import get_version, run | ||
from pkg_resources import parse_version | ||
|
||
LERNA_CMD = "jlpm lerna version --no-push --force-publish --no-git-tag-version" | ||
|
||
|
||
@click.command() | ||
@click.option("--force", default=False, is_flag=True) | ||
@click.argument("spec", nargs=1) | ||
def bump(force, spec): | ||
status = run("git status --porcelain").strip() | ||
if len(status) > 0: | ||
raise Exception("Must be in a clean git state with no untracked files") | ||
|
||
curr = parse_version(get_version()) | ||
if spec == 'next': | ||
spec = f"{curr.major}.{curr.minor}." | ||
if curr.pre: | ||
p, x = curr.pre | ||
spec += f"{curr.micro}{p}{x + 1}" | ||
else: | ||
spec += f"{curr.micro + 1}" | ||
|
||
elif spec == 'patch': | ||
spec = f"{curr.major}.{curr.minor}." | ||
if curr.pre: | ||
spec += f"{curr.micro}" | ||
else: | ||
spec += f"{curr.micro + 1}" | ||
|
||
|
||
version = parse_version(spec) | ||
|
||
# convert the Python version | ||
js_version = f"{version.major}.{version.minor}.{version.micro}" | ||
if version.pre: | ||
p, x = version.pre | ||
p = p.replace("a", "alpha").replace("b", "beta") | ||
js_version += f"-{p}.{x}" | ||
|
||
# bump the JS packages | ||
lerna_cmd = f"{LERNA_CMD} {js_version}" | ||
if force: | ||
lerna_cmd += " --yes" | ||
run(lerna_cmd) | ||
|
||
HERE = Path(__file__).parent.parent.resolve() | ||
path = HERE.joinpath("package.json") | ||
if path.exists(): | ||
with path.open(mode="r") as f: | ||
data = json.load(f) | ||
|
||
data["version"] = js_version | ||
|
||
with path.open(mode="w") as f: | ||
json.dump(data, f, indent=2) | ||
|
||
else: | ||
raise FileNotFoundError(f"Could not find package.json under dir {path!s}") | ||
|
||
|
||
if __name__ == "__main__": | ||
bump() |