Skip to content

Commit 8372efb

Browse files
authored
Allow dev versions (#437)
1 parent e231faf commit 8372efb

File tree

9 files changed

+60
-34
lines changed

9 files changed

+60
-34
lines changed

.github/workflows/check-release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ jobs:
2222
- name: Check Release
2323
uses: ./.github/actions/check-release
2424
with:
25-
version_spec: 10.10.10
2625
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ jobs:
139139
uses: ./.github/actions/prep-release
140140
with:
141141
token: ${{ secrets.GITHUB_TOKEN }}
142-
version_spec: 10.10.10
143142
dry_run: true
144143

145144
- name: populate-release

jupyter_releaser/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
3-
__version__ = "1.0.0a4"
3+
__version__ = "1.0.0.dev0"

jupyter_releaser/changelog.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,6 @@ def update_changelog(changelog_path, entry):
192192
changelog = insert_entry(changelog, entry, version=version)
193193
Path(changelog_path).write_text(changelog, encoding="utf-8")
194194

195-
# Stage changelog
196-
util.run(f"git add {util.normalize_path(changelog_path)}")
197-
198195

199196
def insert_entry(changelog, entry, version=None):
200197
"""Insert the entry into the existing changelog."""
@@ -349,7 +346,7 @@ def extract_current(changelog_path):
349346
def extract_current_version(changelog_path):
350347
"""Extract the current released version from the changelog"""
351348
body = extract_current(changelog_path)
352-
match = re.match(r"#+ ([\d.]+)", body.strip())
349+
match = re.match(r"#+ (\d\S+)", body.strip())
353350
if not match:
354351
raise ValueError("Could not find previous version")
355352
return match.groups()[0]

jupyter_releaser/cli.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def invoke(self, ctx):
5757

5858
# Print a separation header
5959
util.log(f'\n\n{"-" * 50}')
60-
util.log(f"\n{cmd_name}\n")
60+
util.log(f"\n\n{cmd_name}\n\n")
61+
util.log(f'\n\n{"-" * 50}')
6162

6263
if cmd_name in skip or cmd_name.replace("-", "_") in skip:
6364
util.log("*** Skipping based on skip config")
@@ -74,7 +75,7 @@ def invoke(self, ctx):
7475
value = os.environ[str(param.envvar)]
7576
if "token" in name.lower():
7677
value = "***"
77-
util.log(f"Using env value for {name}: {value}")
78+
util.log(f"Using env value for {name}: '{value}'")
7879
continue
7980

8081
# Handle cli and options overrides.
@@ -83,7 +84,9 @@ def invoke(self, ctx):
8384
# Defer to cli overrides
8485
if arg not in ctx.args:
8586
val = options.get(name, options.get(name.replace("_", "-")))
86-
util.log(f"Adding option override for {arg}")
87+
if "token" in arg.lower():
88+
val = "***"
89+
util.log(f"Adding option override for {arg}: '{val}")
8790
if isinstance(val, list):
8891
for v in val:
8992
ctx.args.append(arg)
@@ -93,12 +96,15 @@ def invoke(self, ctx):
9396
ctx.args.append(val)
9497
continue
9598
else:
96-
util.log(f"Using cli arg for {name}")
99+
val = ctx.args[ctx.args.index(arg) + 1]
100+
if "token" in name.lower():
101+
val = "***"
102+
util.log(f"Using cli arg for {name}: '{val}'")
97103
continue
98104

99-
util.log(f"Using default value for {name}")
105+
util.log(f"Using default value for {name}: '{param.default}'")
100106

101-
util.log(f'{"-" * 50}\n\n')
107+
util.log(f'{"~" * 50}\n\n')
102108

103109
# Handle before hooks
104110
before = f"before-{cmd_name}"

jupyter_releaser/lib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ def draft_changelog(
7676
current = changelog.extract_current(changelog_path)
7777
util.log(f"\n\nCurrent Changelog Entry:\n{current}")
7878

79-
# Check out any unstaged files from version bump
80-
# If this is an automated changelog PR, there may be no effective changes
79+
# Check out all changed files.
8180
try:
82-
util.run("git checkout -- .")
81+
util.run("git checkout .", echo=True)
8382
except CalledProcessError as e:
8483
util.log(str(e))
8584
return
8685

86+
util.run("git status", echo=True)
8787
util.log(f"\n\nCreating draft GitHub release for {version}")
8888
owner, repo_name = repo.split("/")
8989
gh = util.get_gh_object(dry_run=dry_run, owner=owner, repo=repo_name, token=auth)

jupyter_releaser/tests/test_functions.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import time
77
from pathlib import Path
88

9-
import pytest
109
import toml
1110
from ghapi.core import GhApi
1211

@@ -298,12 +297,10 @@ def test_bump_version_dev(py_package):
298297
assert util.get_version() == "0.1.0.dev0"
299298
util.bump_version("dev")
300299
assert util.get_version() == "0.1.0.dev1"
301-
with pytest.raises(ValueError):
302-
util.bump_version("next")
303-
with pytest.raises(ValueError):
304-
util.bump_version("patch")
300+
util.bump_version("next")
301+
util.bump_version("patch")
305302
util.bump_version("minor")
306-
assert util.get_version() == "0.1.0"
303+
assert util.get_version() == "0.2.0"
307304

308305

309306
def test_get_config_python(py_package):

jupyter_releaser/util.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def run(cmd, **kwargs):
6363
"""Run a command as a subprocess and get the output as a string"""
6464
quiet_error = kwargs.pop("quiet_error", False)
6565
show_cwd = kwargs.pop("show_cwd", False)
66-
quiet = kwargs.pop("quiet", False)
66+
quiet = kwargs.get("quiet", False)
6767
echo = kwargs.pop("echo", False)
6868

6969
if echo:
@@ -78,7 +78,6 @@ def run(cmd, **kwargs):
7878
# subprocess methods
7979
return _run_win(cmd, **kwargs)
8080

81-
quiet = kwargs.get("quiet")
8281
kwargs.setdefault("check", True)
8382

8483
try:
@@ -281,28 +280,53 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):
281280
# Add some convenience options on top of "tbump" and "hatch"
282281
if "tbump" in version_cmd or "hatch" in version_cmd:
283282
v = parse_version(get_version())
283+
log(f"Current version was: {v}")
284284
assert isinstance(v, Version)
285285

286286
if v.is_devrelease:
287-
# bump from the version in the changelog.
287+
# bump from the version in the changelog unless the spec is dev.
288+
# Import here to avoid circular import.
289+
from jupyter_releaser.changelog import extract_current_version
290+
291+
try:
292+
vc = parse_version(extract_current_version(changelog_path))
293+
log(f"Changelog version was: {vc}")
294+
assert isinstance(vc, Version)
295+
except ValueError:
296+
vc = v
297+
288298
if version_spec in ["patch", "next"]:
289-
raise ValueError(
290-
"We do not support 'patch' or 'next' when dev versions are used, please use an explicit version."
291-
)
299+
if vc.is_prerelease:
300+
if vc.is_devrelease:
301+
# Bump to the next dev release.
302+
assert vc.dev is not None
303+
version_spec = f"{vc.major}.{vc.minor}.{vc.micro}{vc.dev}{vc.dev + 1}"
304+
else:
305+
assert vc.pre is not None
306+
# Bump to the next prerelease.
307+
version_spec = f"{vc.major}.{vc.minor}.{vc.micro}{vc.pre[0]}{vc.pre[1] + 1}"
292308

293-
# Drop the dev portion and move to the minor release.
309+
else:
310+
# Bump to the next micro.
311+
version_spec = f"{vc.major}.{vc.minor}.{vc.micro + 1}"
312+
313+
# Move to the minor release
294314
elif version_spec == "minor":
295-
version_spec = f"{v.major}.{v.minor}.{v.micro}"
315+
version_spec = f"{vc.major}.{v.minor+1}.0"
296316

297317
# Bump to the next dev version.
298318
elif version_spec == "dev":
299319
assert v.dev is not None
300320
version_spec = f"{v.major}.{v.minor}.{v.micro}.dev{v.dev + 1}"
301321

302322
else:
303-
# Bump to next minor for dev.
323+
# Handle dev version spec.
304324
if version_spec == "dev":
305-
version_spec = f"{v.major}.{v.minor + 1}.0.dev0"
325+
if v.pre:
326+
version_spec = f"{v.major}.{v.minor}.{v.micro}.dev0"
327+
# Bump to next minor dev.
328+
else:
329+
version_spec = f"{v.major}.{v.minor + 1}.0.dev0"
306330

307331
# For next, go to next prerelease or patch if it is a final version.
308332
elif version_spec == "next":
@@ -321,7 +345,7 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):
321345
version_spec = f"{v.major}.{v.minor + 1}.0"
322346

323347
# Bump the version
324-
run(f"{version_cmd} {version_spec}")
348+
run(f"{version_cmd} {version_spec}", echo=True)
325349

326350
return get_version()
327351

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["hatchling>=1.0"]
2+
requires = ["hatchling>=1.11"]
33
build-backend = "hatchling.build"
44

55
[project]
@@ -57,10 +57,14 @@ jupyter-releaser = "jupyter_releaser.cli:main"
5757

5858
[tool.hatch.version]
5959
path = "jupyter_releaser/__init__.py"
60+
validate-bump = false
6061

6162
[tool.jupyter-releaser.hooks]
6263
after-populate-release = "bash ./.github/scripts/bump_tag.sh"
6364

65+
[tool.jupyter-releaser.options]
66+
post-version-spec = "dev"
67+
6468
[tool.pytest.ini_options]
6569
addopts = "-raXs --durations 10 --color=yes --doctest-modules"
6670
testpaths = [

0 commit comments

Comments
 (0)