Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to hatch for python version #6544

Merged
merged 5 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .bumpversion.cfg

This file was deleted.

7 changes: 1 addition & 6 deletions .github/workflows/buildutils.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
28 changes: 22 additions & 6 deletions buildutils/src/release-bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -63,15 +60,14 @@ commander

// Handle dry runs.
if (opts.dryRun) {
utils.run(`bumpversion --dry-run --verbose ${spec}`);
return;
}

// If this is a major release during the alpha cycle, bump
// 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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions buildutils/src/release-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion buildutils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
44 changes: 30 additions & 14 deletions notebook/_version.py
Original file line number Diff line number Diff line change
@@ -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<major>\d+)
\.
(?P<minor>\d+)
\.
(?P<micro>\d+)
(?P<releaselevel>((a|b|rc|\.dev)))?
(?P<serial>\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 "",
)
]
)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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"
Expand Down