Skip to content

Commit

Permalink
Merge pull request #89 from QuantStack/bumpVersion
Browse files Browse the repository at this point in the history
Restore `bump-version` script
  • Loading branch information
DenisaCG authored Aug 15, 2024
2 parents a858e27 + ae58759 commit 92f8b72
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ source_dir = "src"
build_dir = "jupyterlab_blockly/labextension"

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

[tool.jupyter-releaser.hooks]
before-build-npm = [
before-bump-version = [
"python -m pip install 'jupyterlab>=4.0.0,<5'",
"jlpm",
"jlpm build:prod"
"jlpm"
]
before-build-npm = [
"YARN_ENABLE_IMMUTABLE_INSTALLS=0 jlpm build:prod"
]
before-build-python = [
# Build the assets
Expand Down
76 changes: 76 additions & 0 deletions scripts/bump-version.py
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()

0 comments on commit 92f8b72

Please sign in to comment.