Skip to content

Commit

Permalink
Fix version bumping for pre-releases (#1610)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
jtpio authored Jun 27, 2022
1 parent a350736 commit 9c4f339
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion demos/restart_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions nbgrader/_version.py
Original file line number Diff line number Diff line change
@@ -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:])
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ We recommand using `conda environment <https://docs.conda.io/en/latest/miniconda
# activate the environment
mamba activate nbgrader

pip install -e ".[docs,tests]"
pip install -e ".[dev,docs,tests]"

Installing Jupyter labextensions
--------------------------------
Expand Down
2 changes: 1 addition & 1 deletion nbgrader/nbextensions/assignment_list/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define([
], function(Jupyter, $, utils, AssignmentList) {
"use strict";

var nbgrader_version = "0.8.0.dev";
var nbgrader_version = "0.8.0.dev0";

var ajax = utils.ajax || $.ajax;
// Notebook v4.3.1 enabled xsrf so use notebooks ajax that includes the
Expand Down
2 changes: 1 addition & 1 deletion nbgrader/nbextensions/course_list/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define([
], function(Jupyter, $, utils, CourseList) {
"use strict";

var nbgrader_version = "0.8.0.dev";
var nbgrader_version = "0.8.0.dev0";

var ajax = utils.ajax || $.ajax;
// Notebook v4.3.1 enabled xsrf so use notebooks ajax that includes the
Expand Down
2 changes: 1 addition & 1 deletion nbgrader/nbextensions/validate_assignment/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define([
], function ($, Jupyter, dialog, utils) {
"use strict";

var nbgrader_version = "0.8.0.dev";
var nbgrader_version = "0.8.0.dev0";

var ajax = utils.ajax || $.ajax;
// Notebook v4.3.1 enabled xsrf so use notebooks ajax that includes the
Expand Down
28 changes: 20 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ npm = ["jlpm"]
[tool.check-manifest]
ignore = ["nbgrader/labextension/**", "yarn.lock"]

[tool.jupyter-releaser.hooks]
after-bump-version = ["python tools/post-bump.py"]

[tool.tbump.version]
current = "0.8.0.dev"
current = "0.8.0.dev0"
regex = '''
(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<channel>dev))?
(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
((?P<channel>a|b|rc|.dev)(?P<release>\d+))?
'''

[tool.tbump.git]
Expand All @@ -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"

Expand All @@ -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 = ""
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ tests =
nbval
requests-mock
wheel
dev =
tbump
toml

[options.entry_points]
console_scripts =
Expand Down
2 changes: 1 addition & 1 deletion src/assignment_list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class AssignmentListWidget extends Widget {
checkNbGraderVersion() {
var warning = this.node.getElementsByClassName('version_error')[0] as HTMLDivElement;
warning.hidden=false;
requestAPI<any>('nbgrader_version?version='+"0.8.0.dev")
requestAPI<any>('nbgrader_version?version='+"0.8.0.dev0")
.then(response => {
if (!response['success']) {
warning.innerText = response['message'];
Expand Down
2 changes: 1 addition & 1 deletion src/course_list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CourseListWidget extends Widget {
}

checkNbGraderVersion() {
let nbgrader_version = '0.8.0.dev';
let nbgrader_version = '0.8.0.dev0';
requestAPI<any>('nbgrader_version?version='+nbgrader_version)
.then(response => {
if (!response['success']) {
Expand Down
2 changes: 1 addition & 1 deletion src/validate_assignment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
27 changes: 27 additions & 0 deletions tools/post-bump.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 9c4f339

Please sign in to comment.