Skip to content

Commit 2ddc356

Browse files
refactor: change the default behaviour in "ap bump" to always bump the dev version (different from "cz bump")
1 parent 3e06da6 commit 2ddc356

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

afterpython/cli/commands/bump.py

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,54 @@
1111
),
1212
)
1313
@click.pass_context
14-
def bump(ctx):
15-
"""Run 'cz bump'"""
16-
subprocess.run(["ap", "cz", "bump", *ctx.args])
14+
@click.option(
15+
"--pre",
16+
is_flag=True,
17+
help="bump to pre-release version (e.g., dev3 -> rc0, a1 -> a2)",
18+
)
19+
@click.option(
20+
"--release", is_flag=True, help="bump to stable release (uses cz bump default)"
21+
)
22+
def bump(ctx, release: bool, pre: bool):
23+
"""Bump project version with granular control.
24+
25+
By default, stays within current release phase:
26+
- Dev releases (e.g., 0.1.0.dev3) -> increment dev number (0.1.0.dev4)
27+
- Pre-releases (e.g., 0.1.0a1) -> increment pre-release (0.1.0a2)
28+
29+
Use --pre to transition from dev to pre-release, or pre-release to next pre-release.
30+
Use --release to bump to next stable version (cz bump default behavior).
31+
"""
32+
from afterpython.tools.pyproject import read_metadata
33+
34+
if release and pre:
35+
raise click.ClickException("Only one of --release or --pre can be specified")
36+
37+
# bump using cz bump's default behavior
38+
if release:
39+
subprocess.run(["ap", "cz", "bump", *ctx.args])
40+
else:
41+
metadata = read_metadata()
42+
version = metadata.version
43+
44+
if version is None:
45+
raise click.ClickException("Unable to read version from pyproject.toml")
46+
47+
args = ctx.args # default: pass through all extra args
48+
49+
# by default, bump dev-release version
50+
if version.is_devrelease and not pre:
51+
devrelease_number = int(version.dev)
52+
if "--devrelease" not in ctx.args:
53+
args = ["--devrelease", str(devrelease_number + 1), *ctx.args]
54+
# exclude e.g. 0.1.0.dev1 which is both dev-release and pre-release (with version.pre = None)
55+
elif version.is_prerelease:
56+
prerelease_type = version.pre[0] if version.pre is not None else "rc"
57+
if prerelease_type == "a":
58+
prerelease_type = "alpha"
59+
elif prerelease_type == "b":
60+
prerelease_type = "beta"
61+
if "--prerelease" not in ctx.args:
62+
args = ["--prerelease", prerelease_type, *ctx.args]
63+
64+
subprocess.run(["ap", "cz", "bump", *args])

afterpython/cli/commands/commitizen.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import subprocess
22

33
import click
4+
from click.exceptions import Exit
45

56

67
@click.command(
@@ -15,4 +16,8 @@ def commitizen(ctx):
1516
"""Run commitizen"""
1617
paths = ctx.obj["paths"]
1718
cz_toml_path = paths.afterpython_path / "cz.toml"
18-
subprocess.run(["cz", "--config", str(cz_toml_path), *ctx.args])
19+
result = subprocess.run(
20+
["cz", "--config", str(cz_toml_path), *ctx.args], check=False
21+
)
22+
if result.returncode != 0:
23+
raise Exit(result.returncode)

afterpython/cli/commands/pre_commit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import subprocess
22

33
import click
4+
from click.exceptions import Exit
45

56

67
def _command_supports_config(command: str) -> bool:
@@ -51,4 +52,6 @@ def pre_commit(ctx):
5152
args.insert(command_idx + 1, "--config")
5253
args.insert(command_idx + 2, str(pre_commit_path))
5354

54-
subprocess.run(["pre-commit", *args], check=True)
55+
result = subprocess.run(["pre-commit", *args], check=False)
56+
if result.returncode != 0:
57+
raise Exit(result.returncode)

0 commit comments

Comments
 (0)