Skip to content

Commit face9d6

Browse files
authored
Fix handling of versions when dev versions are used (#341)
1 parent eb66cf8 commit face9d6

File tree

7 files changed

+58
-12
lines changed

7 files changed

+58
-12
lines changed

jupyter_releaser/actions/draft_release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
os.chdir(curr_dir)
5454

5555

56-
run_action("jupyter-releaser bump-version")
56+
run_action("jupyter-releaser bump-version --use-changelog-version")
5757

5858
with make_group("Handle Check Release"):
5959
if check_release:

jupyter_releaser/changelog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def extract_current(changelog_path):
335335
def extract_current_version(changelog_path):
336336
"""Extract the current released version from the changelog"""
337337
body = extract_current(changelog_path)
338-
match = re.match(r"#+ ([\d.]+)", body.strip())
338+
match = re.match(r"#+ ([\da-z.]+)", body.strip())
339339
if not match:
340340
raise ValueError("Could not find previous version")
341341
return match.groups()[0]

jupyter_releaser/cli.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ def main(force):
203203
),
204204
]
205205

206+
use_changelog_version_options = [
207+
click.option(
208+
"--use-changelog-version",
209+
envvar="RH_USE_CHANGELOG_VERSION",
210+
is_flag=True,
211+
help="Whether to use the changelog version if the current version is a dev version in version bump",
212+
),
213+
]
214+
206215
since_options = [
207216
click.option(
208217
"--since",
@@ -300,14 +309,17 @@ def prep_git(ref, branch, repo, auth, username, git_url):
300309
@add_options(version_spec_options)
301310
@add_options(version_cmd_options)
302311
@add_options(changelog_path_options)
312+
@add_options(use_changelog_version_options)
303313
@add_options(python_packages_options)
304314
@use_checkout_dir()
305-
def bump_version(version_spec, version_cmd, changelog_path, python_packages):
315+
def bump_version(version_spec, version_cmd, changelog_path, use_changelog_version, python_packages):
306316
"""Prep git and env variables and bump version"""
307317
prev_dir = os.getcwd()
308318
for python_package in [p.split(":")[0] for p in python_packages]:
309319
os.chdir(python_package)
310-
lib.bump_version(version_spec, version_cmd, changelog_path)
320+
lib.bump_version(
321+
version_spec, version_cmd, changelog_path, use_changelog_version=use_changelog_version
322+
)
311323
os.chdir(prev_dir)
312324

313325

jupyter_releaser/lib.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
from jupyter_releaser import changelog, npm, python, util
2222

2323

24-
def bump_version(version_spec, version_cmd, changelog_path):
24+
def bump_version(version_spec, version_cmd, changelog_path, use_changelog_version):
2525
"""Bump the version and verify new version"""
26-
util.bump_version(version_spec, version_cmd=version_cmd, changelog_path=changelog_path)
26+
util.bump_version(
27+
version_spec,
28+
version_cmd=version_cmd,
29+
changelog_path=changelog_path,
30+
use_changelog_version=use_changelog_version,
31+
)
2732

2833
version = util.get_version()
2934

@@ -250,7 +255,10 @@ def draft_release(
250255
# Bump to post version if given
251256
if post_version_spec:
252257
post_version = bump_version(
253-
post_version_spec, version_cmd=version_cmd, changelog_path=changelog_path
258+
post_version_spec,
259+
version_cmd=version_cmd,
260+
changelog_path=changelog_path,
261+
use_changelog_version=False,
254262
)
255263
util.log(post_version_message.format(post_version=post_version))
256264
util.run(f'git commit -a -m "Bump to {post_version}"')

jupyter_releaser/tests/test_cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ def test_bump_version(npm_package, runner):
127127
assert version == "1.0.1-rc0"
128128

129129

130+
def test_bump_version_use_changelog(npm_package, runner):
131+
runner(["prep-git", "--git-url", npm_package])
132+
runner(["bump-version", "--use-changelog-version"])
133+
version = util.get_version()
134+
assert version == "1.0.0"
135+
136+
130137
def test_bump_version_bad_version(py_package, runner):
131138
runner(["prep-git", "--git-url", py_package])
132139
with pytest.raises(CalledProcessError):
@@ -173,6 +180,7 @@ def test_list_envvars(runner):
173180
tag-message: RH_TAG_MESSAGE
174181
twine-cmd: TWINE_COMMAND
175182
twine-registry: TWINE_REGISTRY
183+
use-changelog-version: RH_USE_CHANGELOG_VERSION
176184
username: GITHUB_ACTOR
177185
version-cmd: RH_VERSION_COMMAND
178186
version-spec: RH_VERSION_SPEC

jupyter_releaser/tests/test_functions.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,27 @@ def test_bump_version_reg(py_package):
294294

295295

296296
def test_bump_version_dev(py_package):
297+
changelog_path = py_package / "CHANGELOG.md"
297298
util.bump_version("dev")
298299
assert util.get_version() == "0.1.0.dev0"
299300
util.bump_version("dev")
300301
assert util.get_version() == "0.1.0.dev1"
301302
# Should get the version from the changelog
302-
util.bump_version("next", changelog_path=py_package / "CHANGELOG.md")
303+
util.bump_version("next", changelog_path=changelog_path)
303304
assert util.get_version() == "0.0.2"
304305
util.bump_version("dev")
305306
assert util.get_version() == "0.1.0.dev0"
306-
util.bump_version("patch", changelog_path=py_package / "CHANGELOG.md")
307-
assert util.get_version() == "0.0.2"
307+
util.bump_version("patch", changelog_path=changelog_path, use_changelog_version=True)
308+
assert util.get_version() == "0.0.1"
309+
util.bump_version("1.0.0.dev0")
310+
text = changelog_path.read_text(encoding="utf-8")
311+
text = text.replace("0.0.1", "0.0.1a1")
312+
changelog_path.write_text(text, encoding="utf-8")
313+
util.bump_version("patch", changelog_path=changelog_path)
314+
assert util.get_version() == "0.0.1a2"
315+
util.bump_version("1.0.0.dev0")
316+
util.bump_version("patch", changelog_path=changelog_path, use_changelog_version=True)
317+
assert util.get_version() == "0.0.1a1"
308318
util.bump_version("1.0.0.dev0")
309319
util.bump_version("minor")
310320
assert util.get_version() == "1.0.0"

jupyter_releaser/util.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def create_release_commit(version, release_message=None, dist_dir="dist"):
231231
return shas
232232

233233

234-
def bump_version(version_spec, *, changelog_path="", version_cmd=""):
234+
def bump_version(version_spec, *, changelog_path="", version_cmd="", use_changelog_version=False):
235235
"""Bump the version"""
236236
# Look for config files to determine version command if not given
237237
if not version_cmd:
@@ -275,7 +275,15 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):
275275

276276
v = parse_version(extract_current_version(changelog_path))
277277
assert isinstance(v, Version)
278-
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"
278+
if use_changelog_version:
279+
version_spec = v
280+
elif v.is_prerelease:
281+
assert v.pre
282+
# Bump to the next prerelease.
283+
version_spec = f"{v.major}.{v.minor}.{v.micro}{v.pre[0]}{v.pre[1] + 1}"
284+
else:
285+
# Bump to the next micro.
286+
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"
279287

280288
# Drop the dev portion and move to the minor release.
281289
elif version_spec == "minor":

0 commit comments

Comments
 (0)