Merge pull request #6544 from blink1073/use-hatch-version

Switch to hatch for python version
This commit is contained in:
Jeremy Tuloup 2022-09-26 15:24:46 +02:00 committed by GitHub
commit 7364633481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 56 deletions

View File

@ -1,19 +0,0 @@
[bumpversion]
current_version = 7, 0, 0, "alpha", 5
commit = False
tag = False
parse = (?P<major>\d+)\,\ (?P<minor>\d+)\,\ (?P<patch>\d+)\,\ \"(?P<release>\S+)\"\,\ (?P<build>\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]

View File

@ -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"

View File

@ -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');
}
@ -63,7 +60,6 @@ commander
// Handle dry runs.
if (opts.dryRun) {
utils.run(`bumpversion --dry-run --verbose ${spec}`);
return;
}
@ -71,7 +67,7 @@ commander
// just the Python version.
if (prev.indexOf('a') !== -1 && spec === 'major') {
// Bump the version.
utils.run(`bumpversion ${spec}`);
utils.run(`hatch version ${spec}`);
// Run the post-bump script.
postbump(commit);
@ -113,7 +109,27 @@ commander
}
// Bump the version.
utils.run(`bumpversion ${spec} --allow-dirty`);
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 {
pySpec = 'alpha';
}
} 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);

View File

@ -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 =

View File

@ -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];
}

View File

@ -1,22 +1,38 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import re
from collections import namedtuple
# Use "hatch version xx.yy.zz" to handle version changes
__version__ = "7.0.0a5"
# PEP440 version parser
_version_regex = re.compile(
r"""
(?P<major>\d+)
\.
(?P<minor>\d+)
\.
(?P<micro>\d+)
(?P<releaselevel>((a|b|rc|\.dev)))?
(?P<serial>\d+)?
""",
re.VERBOSE,
)
_version_fields = _version_regex.match(__version__).groupdict() # type:ignore
VersionInfo = namedtuple("VersionInfo", ["major", "minor", "micro", "releaselevel", "serial"])
# DO NOT EDIT THIS DIRECTLY! It is managed by bumpversion
version_info = VersionInfo(7, 0, 0, "alpha", 5)
_specifier_ = {"alpha": "a", "beta": "b", "candidate": "rc", "final": ""}
__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 "",
)
]
)

View File

@ -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": [

View File

@ -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"