From f2dcc1cf9f5a72177cfb652db52efab0f9c35983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Wed, 28 Jun 2023 19:26:44 +0200 Subject: [PATCH 1/3] Add support for monorepo version bumps --- package.json | 124 ++++++++++++++++++++-------------------- pyproject.toml | 2 +- scripts/bump_version.py | 69 ++++++++++++++++++++++ 3 files changed, 132 insertions(+), 63 deletions(-) create mode 100644 scripts/bump_version.py diff --git a/package.json b/package.json index f1c45a7b..efb0b7c7 100644 --- a/package.json +++ b/package.json @@ -1,66 +1,66 @@ { - "name": "@jupyter/root-ui-toolkit", - "version": "0.10.1", - "private": true, - "description": "UI Toolkit for Jupyter", - "keywords": [ - "jupyter" + "name": "@jupyter/root-ui-toolkit", + "version": "0.10.0", + "private": true, + "description": "UI Toolkit for Jupyter", + "keywords": [ + "jupyter" + ], + "homepage": "https://jupyterlab-contrib.github.io/jupyter-ui-toolkit/", + "bugs": { + "url": "https://github.com/jupyterlab-contrib/jupyter-ui-toolkit/issues" + }, + "license": "BSD-3-Clause", + "author": { + "name": "Project Jupyter" + }, + "repository": { + "type": "git", + "url": "https://github.com/jupyterlab-contrib/jupyter-ui-toolkit.git" + }, + "workspaces": [ + "packages/*" + ], + "scripts": { + "build": "lerna run build", + "build:prod": "lerna run --scope @jupyter/web-components --scope @jupyter/react-components build && lerna run --scope jupyter-ui-demo build:prod", + "clean": "lerna run clean", + "format": "yarn stylelint && prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"", + "format:check": "yarn stylelint:check && prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"", + "lint": "lerna run eslint", + "lint:check": "lerna run eslint:check", + "stylelint": "yarn stylelint:check --fix", + "stylelint:check": "stylelint --cache \"packages/lab-example/style/**/*.css\"" + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^5.55.0", + "@typescript-eslint/parser": "^5.55.0", + "eslint": "^8.36.0", + "eslint-config-prettier": "^8.7.0", + "eslint-plugin-prettier": "^4.2.1", + "lerna": "^7.0.0", + "prettier": "^2.8.8", + "stylelint": "^14.9.1", + "stylelint-config-prettier": "^9.0.4", + "stylelint-config-recommended": "^8.0.0", + "stylelint-config-standard": "^26.0.0", + "stylelint-prettier": "^2.0.0" + }, + "resolutions": { + "file-system-cache": "<2.4.0 || >2.4.0" + }, + "packageManager": "yarn@3.6.0", + "stylelint": { + "extends": [ + "stylelint-config-recommended", + "stylelint-config-standard", + "stylelint-prettier/recommended" ], - "homepage": "https://jupyterlab-contrib.github.io/jupyter-ui-toolkit/", - "bugs": { - "url": "https://github.com/jupyterlab-contrib/jupyter-ui-toolkit/issues" - }, - "license": "BSD-3-Clause", - "author": { - "name": "Project Jupyter" - }, - "repository": { - "type": "git", - "url": "https://github.com/jupyterlab-contrib/jupyter-ui-toolkit.git" - }, - "workspaces": [ - "packages/*" - ], - "scripts": { - "build": "lerna run build", - "build:prod": "lerna run --scope @jupyter/web-components --scope @jupyter/react-components build && lerna run --scope jupyter-ui-demo build:prod", - "clean": "lerna run clean", - "format": "yarn stylelint && prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"", - "format:check": "yarn stylelint:check && prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"", - "lint": "lerna run eslint", - "lint:check": "lerna run eslint:check", - "stylelint": "yarn stylelint:check --fix", - "stylelint:check": "stylelint --cache \"packages/lab-example/style/**/*.css\"" - }, - "devDependencies": { - "@typescript-eslint/eslint-plugin": "^5.55.0", - "@typescript-eslint/parser": "^5.55.0", - "eslint": "^8.36.0", - "eslint-config-prettier": "^8.7.0", - "eslint-plugin-prettier": "^4.2.1", - "lerna": "^7.0.0", - "prettier": "^2.8.8", - "stylelint": "^14.9.1", - "stylelint-config-prettier": "^9.0.4", - "stylelint-config-recommended": "^8.0.0", - "stylelint-config-standard": "^26.0.0", - "stylelint-prettier": "^2.0.0" - }, - "resolutions": { - "file-system-cache": "<2.4.0 || >2.4.0" - }, - "packageManager": "yarn@3.6.0", - "stylelint": { - "extends": [ - "stylelint-config-recommended", - "stylelint-config-standard", - "stylelint-prettier/recommended" - ], - "rules": { - "property-no-vendor-prefix": null, - "selector-class-pattern": null, - "selector-no-vendor-prefix": null, - "value-no-vendor-prefix": null - } + "rules": { + "property-no-vendor-prefix": null, + "selector-class-pattern": null, + "selector-no-vendor-prefix": null, + "value-no-vendor-prefix": null } + } } diff --git a/pyproject.toml b/pyproject.toml index 5482e5cc..f66df083 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,7 @@ source_dir = "src" build_dir = "jupyter_ui_demo/labextension" [tool.jupyter-releaser.options] -version_cmd = "hatch version" +version_cmd = "python scripts/bump_version.py --force" [tool.jupyter-releaser.hooks] before-build-npm = [ diff --git a/scripts/bump_version.py b/scripts/bump_version.py new file mode 100644 index 00000000..082f7412 --- /dev/null +++ b/scripts/bump_version.py @@ -0,0 +1,69 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. + +import json +from pathlib import Path + +import click +from jupyter_releaser.util import get_version, run +from pkg_resources import parse_version # type: ignore + +LERNA_CMD = "jlpm run 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() From bc257c82c4046d8d0c9ffdc3ff62a36a1bd6d96f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Fri, 30 Jun 2023 14:57:15 +0200 Subject: [PATCH 2/3] Switch from jlpm to yarn --- scripts/bump_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bump_version.py b/scripts/bump_version.py index 082f7412..fa9483c8 100644 --- a/scripts/bump_version.py +++ b/scripts/bump_version.py @@ -8,7 +8,7 @@ from jupyter_releaser.util import get_version, run from pkg_resources import parse_version # type: ignore -LERNA_CMD = "jlpm run lerna version --no-push --force-publish --no-git-tag-version" +LERNA_CMD = "yarn run lerna version --no-push --force-publish --no-git-tag-version" @click.command() From 9102608098a697f186ae1cb25957b9e133645040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Fri, 30 Jun 2023 17:39:50 +0200 Subject: [PATCH 3/3] Run yarn install before bumping version --- scripts/bump_version.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/bump_version.py b/scripts/bump_version.py index fa9483c8..9463f0d1 100644 --- a/scripts/bump_version.py +++ b/scripts/bump_version.py @@ -3,6 +3,7 @@ import json from pathlib import Path +from shutil import which import click from jupyter_releaser.util import get_version, run @@ -45,6 +46,7 @@ def bump(force, spec): js_version += f"-{p}.{x}" # bump the JS packages + run(f"{which('yarn')} install") lerna_cmd = f"{LERNA_CMD} {js_version}" if force: lerna_cmd += " --yes"