Skip to content

Commit e0224f9

Browse files
authored
Merge pull request #287 from blink1073/better-versioning
2 parents d700656 + aa77d23 commit e0224f9

File tree

8 files changed

+91
-22
lines changed

8 files changed

+91
-22
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ Detailed workflows are available to draft a changelog, draft a release, publish
6565
- Checks the links in Markdown and reStructuredText files
6666
- Adds a commit that includes the hashes of the dist files
6767
- Creates an annotated version tag in standard format
68-
- If given, bumps the version using the post version spec
68+
- If given, bumps the version using the post version spec. The post version
69+
spec can also be given as a setting, see the [Write Releaser Config Guide](https://jupyter-releaser.readthedocs.io/en/latest/how_to_guides/write_config.html).
6970
- Pushes the commits and tag to the target `branch`
7071
- Publishes a draft GitHub release for the tag with the changelog entry as the text
7172

docs/source/background/theory.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ Detailed workflows are available to draft a changelog, draft a release, publish
5757
- Checks the links in Markdown and reStructuredText files
5858
- Adds a commit that includes the hashes of the dist files
5959
- Creates an annotated version tag in standard format
60-
- If given, bumps the version using the post version spec
60+
- If given, bumps the version using the post version spec. he post version
61+
spec can also be given as a setting, [Write Releaser Config Guide](../how_to_guides/write_config.html#automatic-dev-versions).
6162
- Pushes the commits and tag to the target `branch`
6263
- Publishes a draft GitHub release for the tag with the changelog entry as the text
6364

docs/source/how_to_guides/write_config.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,15 @@ Example `package.json`:
7272
}
7373
}
7474
```
75+
76+
## Automatic Dev Versions
77+
78+
If you'd like to use dev versions for your repository between builds,
79+
use `dev` as the `post-version-spec` setting, e.g.
80+
81+
```toml
82+
[tools.jupyter-releaser.options]
83+
post-version-spec = "dev"
84+
```
85+
86+
This will bump it to the next minor release with a `.dev0` suffix.

jupyter_releaser/changelog.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,12 @@ def extract_current(changelog_path):
299299
if start != -1 and end != -1:
300300
body = changelog[start + len(START_MARKER) : end]
301301
return body
302+
303+
304+
def extract_current_version(changelog_path):
305+
"""Extract the current released version from the changelog"""
306+
body = extract_current(changelog_path)
307+
match = re.match(r"#+ ([\d.]+)", body.strip())
308+
if not match:
309+
raise ValueError("Could not find previous version")
310+
return match.groups()[0]

jupyter_releaser/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,15 @@ def prep_git(ref, branch, repo, auth, username, git_url):
305305
@main.command()
306306
@add_options(version_spec_options)
307307
@add_options(version_cmd_options)
308+
@add_options(changelog_path_options)
308309
@add_options(python_packages_options)
309310
@use_checkout_dir()
310-
def bump_version(version_spec, version_cmd, python_packages):
311+
def bump_version(version_spec, version_cmd, changelog_path, python_packages):
311312
"""Prep git and env variables and bump version"""
312313
prev_dir = os.getcwd()
313314
for python_package in [p.split(":")[0] for p in python_packages]:
314315
os.chdir(python_package)
315-
lib.bump_version(version_spec, version_cmd)
316+
lib.bump_version(version_spec, version_cmd, changelog_path)
316317
os.chdir(prev_dir)
317318

318319

jupyter_releaser/lib.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
from jupyter_releaser import util
2424

2525

26-
def bump_version(version_spec, version_cmd):
26+
def bump_version(version_spec, version_cmd, changelog_path):
2727
"""Bump the version and verify new version"""
28-
util.bump_version(version_spec, version_cmd=version_cmd)
28+
util.bump_version(
29+
version_spec, version_cmd=version_cmd, changelog_path=changelog_path
30+
)
2931

3032
version = util.get_version()
3133

@@ -237,7 +239,9 @@ def draft_release(
237239

238240
# Bump to post version if given
239241
if post_version_spec:
240-
post_version = bump_version(post_version_spec, version_cmd)
242+
post_version = bump_version(
243+
post_version_spec, version_cmd=version_cmd, changelog_path=changelog_path
244+
)
241245
util.log(post_version_message.format(post_version=post_version))
242246
util.run(f'git commit -a -m "Bump to {post_version}"')
243247

jupyter_releaser/tests/test_functions.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ def test_handle_npm_config(npm_package):
245245
npmrc.write_text(npmrc_text, encoding="utf-8")
246246

247247

248-
def test_bump_version(py_package):
249-
for spec in ["1.0.1", "1.0.1.dev1", "1.0.3a4"]:
248+
def test_bump_version_reg(py_package):
249+
for spec in ["1.0.1", "1.0.3a4"]:
250250
util.bump_version(spec)
251251
util.run("git commit -a -m 'bump version'")
252252
assert util.get_version() == spec
@@ -258,13 +258,27 @@ def test_bump_version(py_package):
258258
util.bump_version("1.0.3a5")
259259
util.bump_version("next")
260260
assert util.get_version() == "1.0.3a6"
261-
util.bump_version("1.0.3.dev1")
262-
util.bump_version("next")
263-
assert util.get_version() == "1.0.3"
264261
util.bump_version("minor")
265262
assert util.get_version() == "1.1.0"
266263

267264

265+
def test_bump_version_dev(py_package):
266+
util.bump_version("dev")
267+
assert util.get_version() == "0.1.0.dev0"
268+
util.bump_version("dev")
269+
assert util.get_version() == "0.1.0.dev1"
270+
# Should get the version from the changelog
271+
util.bump_version("next", changelog_path=py_package / "CHANGELOG.md")
272+
assert util.get_version() == "0.0.2"
273+
util.bump_version("dev")
274+
assert util.get_version() == "0.1.0.dev0"
275+
util.bump_version("patch", changelog_path=py_package / "CHANGELOG.md")
276+
assert util.get_version() == "0.0.2"
277+
util.bump_version("1.0.0.dev0")
278+
util.bump_version("minor")
279+
assert util.get_version() == "1.0.0"
280+
281+
268282
def test_get_config_python(py_package):
269283
Path(util.JUPYTER_RELEASER_CONFIG).unlink()
270284
text = util.PYPROJECT.read_text(encoding="utf-8")

jupyter_releaser/util.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def create_release_commit(version, release_message=None, dist_dir="dist"):
206206
return shas
207207

208208

209-
def bump_version(version_spec, version_cmd=""):
209+
def bump_version(version_spec, *, changelog_path="", version_cmd=""):
210210
"""Bump the version"""
211211
# Look for config files to determine version command if not given
212212
if not version_cmd:
@@ -241,17 +241,44 @@ def bump_version(version_spec, version_cmd=""):
241241
# Add some convenience options on top of "tbump"
242242
if "tbump" in version_cmd:
243243
v = parse_version(get_version())
244-
if version_spec == "next":
245-
if v.is_devrelease:
244+
245+
if v.is_devrelease:
246+
# bump from the version in the changelog.
247+
if version_spec in ["patch", "next"]:
248+
from jupyter_releaser.changelog import extract_current_version
249+
250+
v = parse_version(extract_current_version(changelog_path))
251+
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"
252+
253+
# Drop the dev portion and move to the minor release.
254+
elif version_spec == "minor":
246255
version_spec = f"{v.major}.{v.minor}.{v.micro}"
247-
elif v.is_prerelease:
248-
version_spec = f"{v.major}.{v.minor}.{v.micro}{v.pre[0]}{v.pre[1] + 1}"
249-
else:
256+
257+
# Bump to the next dev version.
258+
elif version_spec == "dev":
259+
version_spec = f"{v.major}.{v.minor}.{v.micro}.dev{v.dev + 1}"
260+
261+
else:
262+
# Bump to next minor for dev.
263+
if version_spec == "dev":
264+
version_spec = f"{v.major}.{v.minor + 1}.0.dev0"
265+
266+
# For next, go to next prerelease or patch if it is a final version.
267+
elif version_spec == "next":
268+
if v.is_prerelease:
269+
version_spec = (
270+
f"{v.major}.{v.minor}.{v.micro}{v.pre[0]}{v.pre[1] + 1}"
271+
)
272+
else:
273+
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"
274+
275+
# For patch, always patch.
276+
elif version_spec == "patch":
250277
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"
251-
elif version_spec == "patch":
252-
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"
253-
elif version_spec == "minor":
254-
version_spec = f"{v.major}.{v.minor + 1}.0"
278+
279+
# For minor, always minor.
280+
elif version_spec == "minor":
281+
version_spec = f"{v.major}.{v.minor + 1}.0"
255282

256283
# Bump the version
257284
run(f"{version_cmd} {version_spec}")

0 commit comments

Comments
 (0)