From 697ba0fea8417c465142aaf85ce48c4ac362d8df Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 23 Sep 2022 12:10:10 -0500 Subject: [PATCH 1/5] 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" From f5866ebbfb0bb72967f47e233cf80dc902d6bc11 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 23 Sep 2022 12:21:39 -0500 Subject: [PATCH 2/5] fix versioning job --- .github/workflows/buildutils.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/buildutils.yml b/.github/workflows/buildutils.yml index 02a53b58d..dffce0155 100644 --- a/.github/workflows/buildutils.yml +++ b/.github/workflows/buildutils.yml @@ -37,12 +37,7 @@ jobs: - name: Reset version run: | - # TODO: improve this with a mock package? - # This step is to ensure the workflow always starts with a final version - sed -i -E 's/= VersionInfo\(.*\)/= VersionInfo\(9, 8, 7, "final", 0\)/' notebook/_version.py - cat notebook/_version.py - sed -i -E 's/current_version = .*/current_version = 9, 8, 7, "final", 0/' .bumpversion.cfg - cat .bumpversion.cfg + hatch version 9.8.7 jlpm run lerna version 9.8.7 --no-push --force-publish --no-git-tag-version --yes git commit -am "Release 9.8.7" From 1f2b68222847fda180cea6a61da6570f36d911dc Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 23 Sep 2022 12:40:15 -0500 Subject: [PATCH 3/5] another attempt --- buildutils/src/release-bump.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/buildutils/src/release-bump.ts b/buildutils/src/release-bump.ts index ec849f23d..ac78258d6 100644 --- a/buildutils/src/release-bump.ts +++ b/buildutils/src/release-bump.ts @@ -51,9 +51,6 @@ commander if (options.indexOf(spec) === -1) { throw new Error(`Version spec must be one of: ${options}`); } - if (isFinal && spec === 'release') { - throw new Error('Use "major" or "minor" to switch back to alpha release'); - } if (isFinal && spec === 'build') { throw new Error('Cannot increment a build on a final release'); } From ca6dd3cf42d20384f503e8c0a0d9816b0acf07c1 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 23 Sep 2022 12:47:23 -0500 Subject: [PATCH 4/5] more version handling --- buildutils/src/release-bump.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/buildutils/src/release-bump.ts b/buildutils/src/release-bump.ts index ac78258d6..39da7fc54 100644 --- a/buildutils/src/release-bump.ts +++ b/buildutils/src/release-bump.ts @@ -109,7 +109,25 @@ commander } // Bump the version. - utils.run(`hatch version ${spec}`); + let pySpec = spec; + if (spec == 'release') { + if (prev.indexOf('a') !== -1) { + pySpec = 'beta'; + } else if (prev.indexOf('b') !== -1) { + pySpec = 'rc'; + } else if (prev.indexOf('rc') !== -1) { + pySpec = 'patch'; + } + } else if (spec == 'build') { + if (prev.indexOf('a') !== -1) { + pySpec = 'a'; + } else if (prev.indexOf('b') !== -1) { + pySpec = 'b'; + } else if (prev.indexOf('rc') !== -1) { + pySpec = 'rc'; + } + } + utils.run(`hatch version ${pySpec}`); // Run the post-bump script. postbump(commit); From 4ebaa3c0b61fe921efdf8e92dcef077186bf9064 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 23 Sep 2022 12:53:55 -0500 Subject: [PATCH 5/5] update version handling again --- buildutils/src/release-bump.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/buildutils/src/release-bump.ts b/buildutils/src/release-bump.ts index 39da7fc54..8abfc38f8 100644 --- a/buildutils/src/release-bump.ts +++ b/buildutils/src/release-bump.ts @@ -67,7 +67,7 @@ commander // just the Python version. if (prev.indexOf('a') !== -1 && spec === 'major') { // Bump the version. - utils.run(`hatch run ${spec}`); + utils.run(`hatch version ${spec}`); // Run the post-bump script. postbump(commit); @@ -117,6 +117,8 @@ commander pySpec = 'rc'; } else if (prev.indexOf('rc') !== -1) { pySpec = 'patch'; + } else { + pySpec = 'alpha'; } } else if (spec == 'build') { if (prev.indexOf('a') !== -1) {