Skip to content

Commit 398523c

Browse files
authored
feat: add --next-phase command to poetry version (#8089)
1 parent fc57323 commit 398523c

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

docs/cli.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,17 @@ The table below illustrates the effect of these rules with concrete examples.
698698
| prerelease | 1.0.3a0 | 1.0.3a1 |
699699
| prerelease | 1.0.3b0 | 1.0.3b1 |
700700

701+
The option `--next-phase` allows the increment of prerelease phase versions.
702+
703+
| rule | before | after |
704+
|-------------------------|----------|----------|
705+
| prerelease --next-phase | 1.0.3a0 | 1.0.3b0 |
706+
| prerelease --next-phase | 1.0.3b0 | 1.0.3rc0 |
707+
| prerelease --next-phase | 1.0.3rc0 | 1.0.3 |
708+
701709
### Options
702710

711+
* `--next-phase`: Increment the phase of the current version.
703712
* `--short (-s)`: Output the version number only.
704713
* `--dry-run`: Do not update pyproject.toml file.
705714

src/poetry/console/commands/version.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class VersionCommand(Command):
2727
"version",
2828
"The version number or the rule to update the version.",
2929
optional=True,
30-
)
30+
),
3131
]
3232
options = [
3333
option("short", "s", "Output the version number only"),
@@ -36,6 +36,7 @@ class VersionCommand(Command):
3636
None,
3737
"Do not update pyproject.toml file",
3838
),
39+
option("next-phase", None, "Increment the phase of the current version"),
3940
]
4041

4142
help = """\
@@ -62,7 +63,7 @@ def handle(self) -> int:
6263

6364
if version:
6465
version = self.increment_version(
65-
self.poetry.package.pretty_version, version
66+
self.poetry.package.pretty_version, version, self.option("next-phase")
6667
)
6768

6869
if self.option("short"):
@@ -91,7 +92,9 @@ def handle(self) -> int:
9192

9293
return 0
9394

94-
def increment_version(self, version: str, rule: str) -> Version:
95+
def increment_version(
96+
self, version: str, rule: str, next_phase: bool = False
97+
) -> Version:
9598
from poetry.core.constraints.version import Version
9699

97100
try:
@@ -115,7 +118,8 @@ def increment_version(self, version: str, rule: str) -> Version:
115118
if parsed.is_unstable():
116119
pre = parsed.pre
117120
assert pre is not None
118-
new = Version(parsed.epoch, parsed.release, pre.next())
121+
pre = pre.next_phase() if next_phase else pre.next()
122+
new = Version(parsed.epoch, parsed.release, pre)
119123
else:
120124
new = parsed.next_patch().first_prerelease()
121125
else:

tests/console/commands/test_version.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ def test_increment_version(
5555
assert command.increment_version(version, rule).text == expected
5656

5757

58+
@pytest.mark.parametrize(
59+
"version, rule, expected",
60+
[
61+
("1.2.3", "prerelease", "1.2.4a0"),
62+
("1.2.3a0", "prerelease", "1.2.3b0"),
63+
("1.2.3a1", "prerelease", "1.2.3b0"),
64+
("1.2.3b1", "prerelease", "1.2.3rc0"),
65+
("1.2.3rc0", "prerelease", "1.2.3"),
66+
("1.2.3-beta.1", "prerelease", "1.2.3rc0"),
67+
("1.2.3-beta1", "prerelease", "1.2.3rc0"),
68+
("1.2.3beta1", "prerelease", "1.2.3rc0"),
69+
],
70+
)
71+
def test_next_phase_version(
72+
version: str, rule: str, expected: str, command: VersionCommand
73+
) -> None:
74+
assert command.increment_version(version, rule, True).text == expected
75+
76+
5877
def test_version_show(tester: CommandTester) -> None:
5978
tester.execute()
6079
assert tester.io.fetch_output() == "simple-project 1.2.3\n"
@@ -75,6 +94,13 @@ def test_short_version_update(tester: CommandTester) -> None:
7594
assert tester.io.fetch_output() == "2.0.0\n"
7695

7796

97+
def test_phase_version_update(tester: CommandTester) -> None:
98+
assert isinstance(tester.command, VersionCommand)
99+
tester.command.poetry.package._set_version("1.2.4a0")
100+
tester.execute("prerelease --next-phase")
101+
assert tester.io.fetch_output() == "Bumping version from 1.2.4a0 to 1.2.4b0\n"
102+
103+
78104
def test_dry_run(tester: CommandTester) -> None:
79105
assert isinstance(tester.command, VersionCommand)
80106
old_pyproject = tester.command.poetry.file.path.read_text()

0 commit comments

Comments
 (0)