From 47f6f514d7e12f707c278f74f2b8375d20e8d778 Mon Sep 17 00:00:00 2001 From: Nuno Date: Sun, 11 Jun 2023 15:57:56 +0100 Subject: [PATCH 1/9] feat: add --next-phase option --- src/poetry/console/commands/version.py | 16 ++++++++++++---- tests/console/commands/test_version.py | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/poetry/console/commands/version.py b/src/poetry/console/commands/version.py index b6953c99c87..39876360e46 100644 --- a/src/poetry/console/commands/version.py +++ b/src/poetry/console/commands/version.py @@ -27,7 +27,7 @@ class VersionCommand(Command): "version", "The version number or the rule to update the version.", optional=True, - ) + ), ] options = [ option("short", "s", "Output the version number only"), @@ -36,6 +36,11 @@ class VersionCommand(Command): None, "Do not update pyproject.toml file", ), + option( + "next-phase", + None, + "Increment the phase of the current version", + ), ] help = """\ @@ -62,7 +67,7 @@ def handle(self) -> int: if version: version = self.increment_version( - self.poetry.package.pretty_version, version + self.poetry.package.pretty_version, version, self.option("next") ) if self.option("short"): @@ -91,7 +96,9 @@ def handle(self) -> int: return 0 - def increment_version(self, version: str, rule: str) -> Version: + def increment_version( + self, version: str, rule: str, next_phase: bool = False + ) -> Version: from poetry.core.constraints.version import Version try: @@ -115,7 +122,8 @@ def increment_version(self, version: str, rule: str) -> Version: if parsed.is_unstable(): pre = parsed.pre assert pre is not None - new = Version(parsed.epoch, parsed.release, pre.next()) + pre = pre.next_phase() if next_phase else pre.next() + new = Version(parsed.epoch, parsed.release, pre) else: new = parsed.next_patch().first_prerelease() else: diff --git a/tests/console/commands/test_version.py b/tests/console/commands/test_version.py index a1d59a3910f..a2fcd41bc6a 100644 --- a/tests/console/commands/test_version.py +++ b/tests/console/commands/test_version.py @@ -55,6 +55,25 @@ def test_increment_version( assert command.increment_version(version, rule).text == expected +@pytest.mark.parametrize( + "version, rule, expected", + [ + ("1.2.3", "prerelease", "1.2.4a0"), + ("1.2.3a0", "prerelease", "1.2.3b0"), + ("1.2.3a1", "prerelease", "1.2.3b0"), + ("1.2.3b1", "prerelease", "1.2.3rc0"), + ("1.2.3rc0", "prerelease", "1.2.3"), + ("1.2.3-beta.1", "prerelease", "1.2.3rc0"), + ("1.2.3-beta1", "prerelease", "1.2.3rc0"), + ("1.2.3beta1", "prerelease", "1.2.3rc0"), + ], +) +def test_next_phase_version( + version: str, rule: str, expected: str, command: VersionCommand +) -> None: + assert command.increment_version(version, rule, True).text == expected + + def test_version_show(tester: CommandTester) -> None: tester.execute() assert tester.io.fetch_output() == "simple-project 1.2.3\n" From e7dd2b2f7a4a9e8769309351059fefdab1c3f41e Mon Sep 17 00:00:00 2001 From: Nuno Date: Sun, 11 Jun 2023 16:11:29 +0100 Subject: [PATCH 2/9] fix: change option name --- src/poetry/console/commands/version.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/poetry/console/commands/version.py b/src/poetry/console/commands/version.py index 39876360e46..0af2a004719 100644 --- a/src/poetry/console/commands/version.py +++ b/src/poetry/console/commands/version.py @@ -36,11 +36,7 @@ class VersionCommand(Command): None, "Do not update pyproject.toml file", ), - option( - "next-phase", - None, - "Increment the phase of the current version", - ), + option("next-phase", None, "Increment the phase of the current version"), ] help = """\ @@ -67,7 +63,7 @@ def handle(self) -> int: if version: version = self.increment_version( - self.poetry.package.pretty_version, version, self.option("next") + self.poetry.package.pretty_version, version, self.option("next-phase") ) if self.option("short"): From be23e582def0113b581fb2b9658b6e74111b96ba Mon Sep 17 00:00:00 2001 From: Nuno Date: Sun, 11 Jun 2023 16:42:30 +0100 Subject: [PATCH 3/9] add documentation --- docs/cli.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/cli.md b/docs/cli.md index b5913b69040..1eb7a09a87e 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -693,8 +693,18 @@ The table below illustrates the effect of these rules with concrete examples. | prerelease | 1.0.3a0 | 1.0.3a1 | | prerelease | 1.0.3b0 | 1.0.3b1 | +The option `--next-phase` allows the increment of prerelease versions. + +| rule | before | after | +| ---------- |---------|---------| +| prerelease --next-phase | 1.0.2 | 1.0.3a0 | +| prerelease --next-phase | 1.0.3a0 | 1.0.3b0 | +| prerelease --next-phase | 1.0.3b0 | 1.0.3rc0 | +| prerelease --next-phase | 1.0.3rc0 | 1.0.3 | + ### Options +* `--next-phase`: Increment the phase of the current version. * `--short (-s)`: Output the version number only. * `--dry-run`: Do not update pyproject.toml file. From 7c179beb6b6bdae73c07fa6551acbf2f9a7afc6f Mon Sep 17 00:00:00 2001 From: Nuno Date: Sun, 11 Jun 2023 16:45:10 +0100 Subject: [PATCH 4/9] fix: documentation --- docs/cli.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 1eb7a09a87e..bcc976c51a2 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -693,11 +693,10 @@ The table below illustrates the effect of these rules with concrete examples. | prerelease | 1.0.3a0 | 1.0.3a1 | | prerelease | 1.0.3b0 | 1.0.3b1 | -The option `--next-phase` allows the increment of prerelease versions. +The option `--next-phase` allows the increment of prerelease phase versions. | rule | before | after | | ---------- |---------|---------| -| prerelease --next-phase | 1.0.2 | 1.0.3a0 | | prerelease --next-phase | 1.0.3a0 | 1.0.3b0 | | prerelease --next-phase | 1.0.3b0 | 1.0.3rc0 | | prerelease --next-phase | 1.0.3rc0 | 1.0.3 | From e35ee9cecf7646a2fc412d65a78c566880f5f5a4 Mon Sep 17 00:00:00 2001 From: Nuno Date: Sun, 10 Sep 2023 13:25:04 +0100 Subject: [PATCH 5/9] chore: align phase table --- docs/cli.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index bcc976c51a2..3f52641c5d5 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -695,11 +695,11 @@ The table below illustrates the effect of these rules with concrete examples. The option `--next-phase` allows the increment of prerelease phase versions. -| rule | before | after | -| ---------- |---------|---------| -| prerelease --next-phase | 1.0.3a0 | 1.0.3b0 | -| prerelease --next-phase | 1.0.3b0 | 1.0.3rc0 | -| prerelease --next-phase | 1.0.3rc0 | 1.0.3 | +| rule | before | after | +| ---------- |--------- |--------- | +| prerelease --next-phase | 1.0.3a0 | 1.0.3b0 | +| prerelease --next-phase | 1.0.3b0 | 1.0.3rc0 | +| prerelease --next-phase | 1.0.3rc0 | 1.0.3 | ### Options From 40af032dcffdd66e9ccdb9fd31871399757cfb67 Mon Sep 17 00:00:00 2001 From: Nuno Date: Sun, 10 Sep 2023 14:10:10 +0100 Subject: [PATCH 6/9] test: next-phase command line --- tests/console/commands/test_version.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/console/commands/test_version.py b/tests/console/commands/test_version.py index a2fcd41bc6a..6b4d9d1aeda 100644 --- a/tests/console/commands/test_version.py +++ b/tests/console/commands/test_version.py @@ -94,6 +94,11 @@ def test_short_version_update(tester: CommandTester) -> None: assert tester.io.fetch_output() == "2.0.0\n" +def test_phase_version_update(tester: CommandTester) -> None: + tester.execute("prerelease --next-phase") + assert tester.io.fetch_output() == "Bumping version from 1.2.3 to 1.2.4a0\n" + + def test_dry_run(tester: CommandTester) -> None: assert isinstance(tester.command, VersionCommand) old_pyproject = tester.command.poetry.file.path.read_text() From abd6a35583a3f5d253277d5dc4d8a9215551a3d9 Mon Sep 17 00:00:00 2001 From: Nuno Date: Sun, 10 Sep 2023 16:49:12 +0100 Subject: [PATCH 7/9] test: correctly test --next-phase --- tests/console/commands/test_version.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/console/commands/test_version.py b/tests/console/commands/test_version.py index 6b4d9d1aeda..19ff6062ba8 100644 --- a/tests/console/commands/test_version.py +++ b/tests/console/commands/test_version.py @@ -95,8 +95,9 @@ def test_short_version_update(tester: CommandTester) -> None: def test_phase_version_update(tester: CommandTester) -> None: + tester.command.poetry.package._set_version("1.2.4a0") tester.execute("prerelease --next-phase") - assert tester.io.fetch_output() == "Bumping version from 1.2.3 to 1.2.4a0\n" + assert tester.io.fetch_output() == "Bumping version from 1.2.4a0 to 1.2.4b0\n" def test_dry_run(tester: CommandTester) -> None: From 29dd903fdbe88f2bced2693d37c45846702b8c67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sun, 10 Sep 2023 19:01:37 +0200 Subject: [PATCH 8/9] fix mypy --- tests/console/commands/test_version.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/console/commands/test_version.py b/tests/console/commands/test_version.py index 19ff6062ba8..8d671273bbb 100644 --- a/tests/console/commands/test_version.py +++ b/tests/console/commands/test_version.py @@ -95,6 +95,7 @@ def test_short_version_update(tester: CommandTester) -> None: def test_phase_version_update(tester: CommandTester) -> None: + assert isinstance(tester.command, VersionCommand) tester.command.poetry.package._set_version("1.2.4a0") tester.execute("prerelease --next-phase") assert tester.io.fetch_output() == "Bumping version from 1.2.4a0 to 1.2.4b0\n" From 3585a706b4a0de0d9728b5ced867c3ff45eb06f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sun, 10 Sep 2023 19:01:50 +0200 Subject: [PATCH 9/9] style --- docs/cli.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cli.md b/docs/cli.md index 3f52641c5d5..3e1c9afcb66 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -696,7 +696,7 @@ The table below illustrates the effect of these rules with concrete examples. The option `--next-phase` allows the increment of prerelease phase versions. | rule | before | after | -| ---------- |--------- |--------- | +|-------------------------|----------|----------| | prerelease --next-phase | 1.0.3a0 | 1.0.3b0 | | prerelease --next-phase | 1.0.3b0 | 1.0.3rc0 | | prerelease --next-phase | 1.0.3rc0 | 1.0.3 |