From fbc64656cca8720b85ea04e5e01ba42f9cd2a6b1 Mon Sep 17 00:00:00 2001 From: Etty Date: Fri, 13 May 2022 20:04:06 +0100 Subject: [PATCH 1/7] Add --dry-run option to version command --- src/poetry/console/commands/version.py | 16 ++++++++++------ tests/console/commands/test_version.py | 6 ++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/poetry/console/commands/version.py b/src/poetry/console/commands/version.py index 7b5744d6171..62b5b195484 100644 --- a/src/poetry/console/commands/version.py +++ b/src/poetry/console/commands/version.py @@ -29,7 +29,10 @@ class VersionCommand(Command): optional=True, ) ] - options = [option("short", "s", "Output the version number only")] + options = [ + option("short", "s", "Output the version number only"), + option("dry-run", None, "Perform all actions except upload the package."), + ] help = """\ The version command shows the current version of the project or bumps the version of @@ -66,12 +69,13 @@ def handle(self) -> None: f" to {version}" ) - content: dict[str, Any] = self.poetry.file.read() - poetry_content = content["tool"]["poetry"] - poetry_content["version"] = version.text + if not self.option("dry-run"): + content: dict[str, Any] = self.poetry.file.read() + poetry_content = content["tool"]["poetry"] + poetry_content["version"] = version.text - assert isinstance(content, TOMLDocument) - self.poetry.file.write(content) + assert isinstance(content, TOMLDocument) + self.poetry.file.write(content) else: if self.option("short"): self.line(self.poetry.package.pretty_version) diff --git a/tests/console/commands/test_version.py b/tests/console/commands/test_version.py index bd93589412b..ac1a53757c0 100644 --- a/tests/console/commands/test_version.py +++ b/tests/console/commands/test_version.py @@ -76,3 +76,9 @@ def test_version_update(tester: CommandTester): def test_short_version_update(tester: CommandTester): tester.execute("--short 2.0.0") assert tester.io.fetch_output() == "2.0.0\n" + + +def test_dry_run(tester: CommandTester): + content = tester.command.poetry.file.path.read_text() + tester.execute("--dry-run major") + assert content == tester.command.poetry.file.path.read_text() From 883e6ea3fd54ba87bab3a2514e6c2f938df16355 Mon Sep 17 00:00:00 2001 From: Etty Date: Fri, 13 May 2022 20:10:00 +0100 Subject: [PATCH 2/7] Update documentation --- docs/cli.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/cli.md b/docs/cli.md index 7b8ca165988..2abc8140717 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -622,6 +622,7 @@ The table below illustrates the effect of these rules with concrete examples. ### Options * `--short (-s)`: Output the version number only. +* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose). ## export From 7f6583cf519f3d48fb053aa080997e0e9774ce73 Mon Sep 17 00:00:00 2001 From: Etty Date: Fri, 13 May 2022 20:16:26 +0100 Subject: [PATCH 3/7] Update test --- tests/console/commands/test_version.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/console/commands/test_version.py b/tests/console/commands/test_version.py index ac1a53757c0..5274c3ac497 100644 --- a/tests/console/commands/test_version.py +++ b/tests/console/commands/test_version.py @@ -79,6 +79,8 @@ def test_short_version_update(tester: CommandTester): def test_dry_run(tester: CommandTester): - content = tester.command.poetry.file.path.read_text() + old_pyproject = tester.command.poetry.file.path.read_text() tester.execute("--dry-run major") - assert content == tester.command.poetry.file.path.read_text() + assert tester.io.fetch_output() == "Bumping version from 1.2.3 to 2.0.0\n" + new_pyproject = tester.command.poetry.file.path.read_text() + assert old_pyproject == new_pyproject From 8bb8c285970d5f37df7adde106321a79c9cadd02 Mon Sep 17 00:00:00 2001 From: Etty Date: Fri, 13 May 2022 20:38:10 +0100 Subject: [PATCH 4/7] Update command description --- docs/cli.md | 2 +- src/poetry/console/commands/version.py | 2 +- tests/console/commands/test_version.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 2abc8140717..8618942e2fe 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -622,7 +622,7 @@ The table below illustrates the effect of these rules with concrete examples. ### Options * `--short (-s)`: Output the version number only. -* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose). +* `--dry-run`: Output the operations but do not execute anything. ## export diff --git a/src/poetry/console/commands/version.py b/src/poetry/console/commands/version.py index 62b5b195484..52134f691db 100644 --- a/src/poetry/console/commands/version.py +++ b/src/poetry/console/commands/version.py @@ -31,7 +31,7 @@ class VersionCommand(Command): ] options = [ option("short", "s", "Output the version number only"), - option("dry-run", None, "Perform all actions except upload the package."), + option("dry-run", None, "Outputs the operations but will not execute anything"), ] help = """\ diff --git a/tests/console/commands/test_version.py b/tests/console/commands/test_version.py index 5274c3ac497..36487a3f38a 100644 --- a/tests/console/commands/test_version.py +++ b/tests/console/commands/test_version.py @@ -81,6 +81,7 @@ def test_short_version_update(tester: CommandTester): def test_dry_run(tester: CommandTester): old_pyproject = tester.command.poetry.file.path.read_text() tester.execute("--dry-run major") - assert tester.io.fetch_output() == "Bumping version from 1.2.3 to 2.0.0\n" + new_pyproject = tester.command.poetry.file.path.read_text() + assert tester.io.fetch_output() == "Bumping version from 1.2.3 to 2.0.0\n" assert old_pyproject == new_pyproject From 7de767999a524c44bee850982131124b75b89731 Mon Sep 17 00:00:00 2001 From: Etty Date: Sun, 15 May 2022 17:40:15 +0100 Subject: [PATCH 5/7] Rephrase dry-run option description --- src/poetry/console/commands/version.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/poetry/console/commands/version.py b/src/poetry/console/commands/version.py index 52134f691db..d7acf7c17fc 100644 --- a/src/poetry/console/commands/version.py +++ b/src/poetry/console/commands/version.py @@ -31,7 +31,11 @@ class VersionCommand(Command): ] options = [ option("short", "s", "Output the version number only"), - option("dry-run", None, "Outputs the operations but will not execute anything"), + option( + "dry-run", + None, + "Outputs the version without updating the pyproject.toml file", + ), ] help = """\ From 565541b82f33c08cd2588d06e341d64cc12ba102 Mon Sep 17 00:00:00 2001 From: Etty <28976199+estyxx@users.noreply.github.com> Date: Mon, 16 May 2022 10:55:44 +0100 Subject: [PATCH 6/7] Update src/poetry/console/commands/version.py Co-authored-by: Arun Babu Neelicattu --- src/poetry/console/commands/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poetry/console/commands/version.py b/src/poetry/console/commands/version.py index d7acf7c17fc..28b3c6815f3 100644 --- a/src/poetry/console/commands/version.py +++ b/src/poetry/console/commands/version.py @@ -34,7 +34,7 @@ class VersionCommand(Command): option( "dry-run", None, - "Outputs the version without updating the pyproject.toml file", + "Do not update pyproject.toml file", ), ] From c4a9d9f61fc03a7dcab5bd0ddd6f6c0f95a81722 Mon Sep 17 00:00:00 2001 From: Etty Date: Mon, 16 May 2022 10:57:06 +0100 Subject: [PATCH 7/7] Update doc --- docs/cli.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cli.md b/docs/cli.md index 8618942e2fe..0f954fa6f59 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -622,7 +622,7 @@ The table below illustrates the effect of these rules with concrete examples. ### Options * `--short (-s)`: Output the version number only. -* `--dry-run`: Output the operations but do not execute anything. +* `--dry-run`: Do not update pyproject.toml file. ## export