From 697ba0fea8417c465142aaf85ce48c4ac362d8df Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 23 Sep 2022 12:10:10 -0500 Subject: [PATCH] switch to hatch for python version --- .bumpversion.cfg | 19 -------------- buildutils/src/release-bump.ts | 5 ++-- buildutils/src/release-patch.ts | 5 +--- buildutils/src/utils.ts | 2 +- notebook/_version.py | 44 ++++++++++++++++++++++----------- package.json | 2 +- pyproject.toml | 6 ++--- 7 files changed, 37 insertions(+), 46 deletions(-) delete mode 100644 .bumpversion.cfg diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index d0bb6b90a..000000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,19 +0,0 @@ -[bumpversion] -current_version = 7, 0, 0, "alpha", 5 -commit = False -tag = False -parse = (?P\d+)\,\ (?P\d+)\,\ (?P\d+)\,\ \"(?P\S+)\"\,\ (?P\d+) -serialize = - {major}, {minor}, {patch}, "{release}", {build} - -[bumpversion:part:release] -optional_value = final -values = - alpha - beta - candidate - final - -[bumpversion:part:build] - -[bumpversion:file:notebook/_version.py] diff --git a/buildutils/src/release-bump.ts b/buildutils/src/release-bump.ts index e942c7ada..ec849f23d 100644 --- a/buildutils/src/release-bump.ts +++ b/buildutils/src/release-bump.ts @@ -63,7 +63,6 @@ commander // Handle dry runs. if (opts.dryRun) { - utils.run(`bumpversion --dry-run --verbose ${spec}`); return; } @@ -71,7 +70,7 @@ commander // just the Python version. if (prev.indexOf('a') !== -1 && spec === 'major') { // Bump the version. - utils.run(`bumpversion ${spec}`); + utils.run(`hatch run ${spec}`); // Run the post-bump script. postbump(commit); @@ -113,7 +112,7 @@ commander } // Bump the version. - utils.run(`bumpversion ${spec} --allow-dirty`); + utils.run(`hatch version ${spec}`); // Run the post-bump script. postbump(commit); diff --git a/buildutils/src/release-patch.ts b/buildutils/src/release-patch.ts index df72a1639..612e38977 100644 --- a/buildutils/src/release-patch.ts +++ b/buildutils/src/release-patch.ts @@ -33,10 +33,7 @@ commander utils.prebump(); // Patch the python version - utils.run('bumpversion patch'); // switches to alpha - utils.run('bumpversion release --allow-dirty'); // switches to beta - utils.run('bumpversion release --allow-dirty'); // switches to rc. - utils.run('bumpversion release --allow-dirty'); // switches to final. + utils.run('hatch version patch'); // Version the changed let cmd = diff --git a/buildutils/src/utils.ts b/buildutils/src/utils.ts index de98bd3e5..b48a81764 100644 --- a/buildutils/src/utils.ts +++ b/buildutils/src/utils.ts @@ -4,7 +4,7 @@ import { run } from '@jupyterlab/buildutils'; * Get the current version of notebook */ export function getPythonVersion(): string { - const cmd = 'hatchling version'; + const cmd = 'hatch version'; const lines = run(cmd, { stdio: 'pipe' }, true).split('\n'); return lines[lines.length - 1]; } diff --git a/notebook/_version.py b/notebook/_version.py index 2633268e3..c060d482b 100644 --- a/notebook/_version.py +++ b/notebook/_version.py @@ -1,22 +1,38 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. - +import re from collections import namedtuple -VersionInfo = namedtuple("VersionInfo", ["major", "minor", "micro", "releaselevel", "serial"]) +# Use "hatch version xx.yy.zz" to handle version changes +__version__ = "7.0.0a5" -# DO NOT EDIT THIS DIRECTLY! It is managed by bumpversion -version_info = VersionInfo(7, 0, 0, "alpha", 5) +# PEP440 version parser +_version_regex = re.compile( + r""" + (?P\d+) + \. + (?P\d+) + \. + (?P\d+) + (?P((a|b|rc|\.dev)))? + (?P\d+)? + """, + re.VERBOSE, +) -_specifier_ = {"alpha": "a", "beta": "b", "candidate": "rc", "final": ""} +_version_fields = _version_regex.match(__version__).groupdict() # type:ignore + +VersionInfo = namedtuple("VersionInfo", ["major", "minor", "micro", "releaselevel", "serial"]) -__version__ = "{}.{}.{}{}".format( - version_info.major, - version_info.minor, - version_info.micro, - ( - "" - if version_info.releaselevel == "final" - else _specifier_[version_info.releaselevel] + str(version_info.serial) - ), +version_info = VersionInfo( + *[ + field + for field in ( + int(_version_fields["major"]), + int(_version_fields["minor"]), + int(_version_fields["micro"]), + _version_fields["releaselevel"] or "", + _version_fields["serial"] or "", + ) + ] ) diff --git a/package.json b/package.json index ae9a92d8b..ba70f0c93 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "before-build-python": [ "jlpm clean" ], - "before-bump-version": "python -m pip install bump2version" + "before-bump-version": "python -m pip install hatch" }, "options": { "version-cmd": [ diff --git a/pyproject.toml b/pyproject.toml index 58947627d..617736625 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["hatchling>=1.0", "jupyterlab>=4.0.0a25,<5", "ypy-websocket==0.2"] +requires = ["hatchling>=1.5", "jupyterlab>=4.0.0a25,<5", "ypy-websocket==0.2"] build-backend = "hatchling.build" [project] @@ -62,13 +62,11 @@ test = [ ] dev = [ "pre-commit", - "bump2version", - "hatchling" + "hatch" ] [tool.hatch.version] path = "notebook/_version.py" -source = "code" [tool.hatch.build.targets.wheel.shared-data] "notebook/labextension" = "share/jupyter/labextensions/@jupyter-notebook/lab-extension"