From 9c4f339b34e46f29a86e6cc873c68bc3d954de28 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Mon, 27 Jun 2022 14:34:33 +0200 Subject: [PATCH] Fix version bumping for pre-releases (#1610) * Fix version bumping for pre-releases * Fix extra . * Set to 0.8.0.dev0 * Bump more files * Fix _version.py * Fix version_template * Add default value for release * Add hook to set the version in package.json * Install with dev in the check releaser workflow * Replace with `-dev` --- .github/workflows/check-release.yml | 2 +- demos/restart_demo.sh | 2 +- nbgrader/_version.py | 4 +-- .../installation_developer.rst | 2 +- nbgrader/nbextensions/assignment_list/main.js | 2 +- nbgrader/nbextensions/course_list/main.js | 2 +- .../nbextensions/validate_assignment/main.js | 2 +- pyproject.toml | 28 +++++++++++++------ setup.cfg | 2 ++ src/assignment_list/index.ts | 2 +- src/course_list/index.ts | 2 +- src/validate_assignment/index.ts | 2 +- tools/post-bump.py | 27 ++++++++++++++++++ 13 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 tools/post-bump.py diff --git a/.github/workflows/check-release.yml b/.github/workflows/check-release.yml index 37490b37a..5d903bcd3 100644 --- a/.github/workflows/check-release.yml +++ b/.github/workflows/check-release.yml @@ -19,7 +19,7 @@ jobs: uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - name: Install Dependencies run: | - pip install -e . + pip install -e ".[dev]" - name: Check Release if: ${{ matrix.group == 'check_release' }} uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v1 diff --git a/demos/restart_demo.sh b/demos/restart_demo.sh index 75c0227ad..f23f7bfef 100755 --- a/demos/restart_demo.sh +++ b/demos/restart_demo.sh @@ -48,7 +48,7 @@ install_nbgrader () { git pull # Install requirements and nbgrader. - pip3 install -e ".[docs,tests]" + pip3 install -e ".[dev,docs,tests]" # Install global extensions, and disable them globally. We will re-enable # specific ones for different user accounts in each demo. diff --git a/nbgrader/_version.py b/nbgrader/_version.py index feacc57a0..d1de8d60e 100644 --- a/nbgrader/_version.py +++ b/nbgrader/_version.py @@ -1,2 +1,2 @@ -version_info = (0, 8, 0, "dev") -__version__ = '.'.join(map(str, version_info[:3])) + (("." + version_info[3]) if version_info[3] else "") +version_info = (0, 8, 0, ".dev", "0") +__version__ = ".".join(map(str, version_info[:3])) + "".join(version_info[3:]) diff --git a/nbgrader/docs/source/contributor_guide/installation_developer.rst b/nbgrader/docs/source/contributor_guide/installation_developer.rst index 09bc7cd38..c1de9aca4 100644 --- a/nbgrader/docs/source/contributor_guide/installation_developer.rst +++ b/nbgrader/docs/source/contributor_guide/installation_developer.rst @@ -20,7 +20,7 @@ We recommand using `conda environment \d+)\.(?P\d+)\.(?P\d+)(\.(?Pdev))? + (?P\d+)\.(?P\d+)\.(?P\d+) + ((?Pa|b|rc|.dev)(?P\d+))? ''' [tool.tbump.git] @@ -32,16 +36,11 @@ cmd = "grep -q {new_version} CHANGELOG.md" [[tool.tbump.file]] src = "nbgrader/_version.py" -version_template = '({major}, {minor}, {patch}, "{channel}")' +version_template = '({major}, {minor}, {patch}, "{channel}", "{release}")' [[tool.tbump.file]] src = "pyproject.toml" -[[tool.tbump.file]] -src = "package.json" -version_template = "{major}.{minor}.{patch}" -search = '"version": "{current_version}"' - [[tool.tbump.file]] src = "nbgrader/nbextensions/assignment_list/main.js" @@ -51,6 +50,19 @@ src = "nbgrader/nbextensions/course_list/main.js" [[tool.tbump.file]] src = "nbgrader/nbextensions/validate_assignment/main.js" +[[tool.tbump.file]] +src = "src/assignment_list/index.ts" + +[[tool.tbump.file]] +src = "src/course_list/index.ts" + +[[tool.tbump.file]] +src = "src/validate_assignment/index.ts" + [[tool.tbump.field]] name = "channel" default = "" + +[[tool.tbump.field]] +name = "release" +default = "" diff --git a/setup.cfg b/setup.cfg index 7010c390f..6dfefcd6b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,7 +63,9 @@ tests = nbval requests-mock wheel +dev = tbump + toml [options.entry_points] console_scripts = diff --git a/src/assignment_list/index.ts b/src/assignment_list/index.ts index afee10422..61d3cb9c8 100644 --- a/src/assignment_list/index.ts +++ b/src/assignment_list/index.ts @@ -150,7 +150,7 @@ class AssignmentListWidget extends Widget { checkNbGraderVersion() { var warning = this.node.getElementsByClassName('version_error')[0] as HTMLDivElement; warning.hidden=false; - requestAPI('nbgrader_version?version='+"0.8.0.dev") + requestAPI('nbgrader_version?version='+"0.8.0.dev0") .then(response => { if (!response['success']) { warning.innerText = response['message']; diff --git a/src/course_list/index.ts b/src/course_list/index.ts index a91bf7e15..e3d149e72 100644 --- a/src/course_list/index.ts +++ b/src/course_list/index.ts @@ -80,7 +80,7 @@ class CourseListWidget extends Widget { } checkNbGraderVersion() { - let nbgrader_version = '0.8.0.dev'; + let nbgrader_version = '0.8.0.dev0'; requestAPI('nbgrader_version?version='+nbgrader_version) .then(response => { if (!response['success']) { diff --git a/src/validate_assignment/index.ts b/src/validate_assignment/index.ts index 80b9235e1..fb2265590 100644 --- a/src/validate_assignment/index.ts +++ b/src/validate_assignment/index.ts @@ -23,7 +23,7 @@ import { requestAPI } from './validateassignment'; import { showNbGraderDialog, validate } from '../common/validate'; -var nbgrader_version = "0.8.0.dev"; // TODO: hardcoded value +var nbgrader_version = "0.8.0.dev0"; // TODO: hardcoded value const PLUGIN_ID = "nbgrader/validate-assignment" diff --git a/tools/post-bump.py b/tools/post-bump.py new file mode 100644 index 000000000..3812c307f --- /dev/null +++ b/tools/post-bump.py @@ -0,0 +1,27 @@ +import json +from pathlib import Path + +import toml + +ENC = dict(encoding="utf-8") +ROOT = Path(__file__).parent.parent +PYPROJECT = ROOT / "pyproject.toml" +PACKAGE_JSON = ROOT / "package.json" + + +def main(): + # read the Python version + pyproject = PYPROJECT.read_text(**ENC) + data = toml.loads(pyproject) + project = data.get("tool", {}).get("tbump", {}).get("version", {}) + py_version = project.get("current") + + # set the JS version + js_version = py_version.replace("a", "-alpha").replace("b", "-beta").replace("rc", "-rc").replace(".dev", "-dev") + package_json = json.loads(PACKAGE_JSON.read_text(**ENC)) + package_json["version"] = js_version + PACKAGE_JSON.write_text(json.dumps(package_json, indent=2), **ENC) + + +if __name__ == "__main__": + main()