From 8839ced58e78254721325f178f576d797960af89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:37:07 +0200 Subject: [PATCH] do not remove `--dev`, revoke deprecation --- docs/cli.md | 2 ++ src/poetry/console/commands/add.py | 10 ++++++++- src/poetry/console/commands/remove.py | 12 ++++++++++- tests/console/commands/test_add.py | 29 +++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 8c8d6dd819e..f8cd49cc1fc 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -448,6 +448,7 @@ about dependency groups. ### Options * `--group (-G)`: The group to add the dependency to. +* `--dev (-D)`: Add package as development dependency. (shortcut for `-G dev`) * `--editable (-e)`: Add vcs/path dependencies as editable. * `--extras (-E)`: Extras to activate for the dependency. (multiple values allowed) * `--optional`: Add as an optional dependency to an extra. @@ -480,6 +481,7 @@ about dependency groups. ### Options * `--group (-G)`: The group to remove the dependency from. +* `--dev (-D)`: Removes a package from the development dependencies. (shortcut for `-G dev`) * `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose). * `--lock`: Do not perform operations (only update the lockfile). diff --git a/src/poetry/console/commands/add.py b/src/poetry/console/commands/add.py index 59f87e4f762..cfd7bc009a1 100644 --- a/src/poetry/console/commands/add.py +++ b/src/poetry/console/commands/add.py @@ -40,6 +40,11 @@ class AddCommand(InstallerCommand, InitCommand): flag=False, default=MAIN_GROUP, ), + option( + "dev", + "D", + "Add as a development dependency. (shortcut for '-G dev')", + ), option("editable", "e", "Add vcs/path dependencies as editable."), option( "extras", @@ -122,7 +127,10 @@ def handle(self) -> int: from poetry.factory import Factory packages = self.argument("name") - group = self.option("group", self.default_group or MAIN_GROUP) + if self.option("dev"): + group = "dev" + else: + group = self.option("group", self.default_group or MAIN_GROUP) if self.option("extras") and len(packages) > 1: raise ValueError( diff --git a/src/poetry/console/commands/remove.py b/src/poetry/console/commands/remove.py index 22941fa08d6..a4ce37fc44a 100644 --- a/src/poetry/console/commands/remove.py +++ b/src/poetry/console/commands/remove.py @@ -28,6 +28,12 @@ class RemoveCommand(InstallerCommand): ] options: ClassVar[list[Option]] = [ option("group", "G", "The group to remove the dependency from.", flag=False), + option( + "dev", + "D", + "Remove a package from the development dependencies." + " (shortcut for '-G dev')", + ), option( "dry-run", None, @@ -49,7 +55,11 @@ class RemoveCommand(InstallerCommand): def handle(self) -> int: packages = self.argument("packages") - group = self.option("group", self.default_group) + + if self.option("dev"): + group = "dev" + else: + group = self.option("group", self.default_group) content: dict[str, Any] = self.poetry.file.read() project_content = content.get("project", {}) diff --git a/tests/console/commands/test_add.py b/tests/console/commands/test_add.py index ab5889c63ea..9c7509d7c52 100644 --- a/tests/console/commands/test_add.py +++ b/tests/console/commands/test_add.py @@ -1099,6 +1099,35 @@ def test_add_creating_poetry_section_does_not_remove_existing_tools( assert pyproject["tool"]["foo"]["key"] == "value" +def test_add_to_dev_section(app: PoetryTestApplication, tester: CommandTester) -> None: + tester.execute("cachy --dev") + + expected = """\ +Using version ^0.2.0 for cachy + +Updating dependencies +Resolving dependencies... + +Package operations: 2 installs, 0 updates, 0 removals + + - Installing msgpack-python (0.5.6) + - Installing cachy (0.2.0) + +Writing lock file +""" + + assert tester.io.fetch_error() == "" + assert tester.io.fetch_output() == expected + assert isinstance(tester.command, InstallerCommand) + assert tester.command.installer.executor.installations_count == 2 + + pyproject: dict[str, Any] = app.poetry.file.read() + content = pyproject["tool"]["poetry"] + + assert "cachy" in content["group"]["dev"]["dependencies"] + assert content["group"]["dev"]["dependencies"]["cachy"] == "^0.2.0" + + def test_add_should_not_select_prereleases( app: PoetryTestApplication, tester: CommandTester ) -> None: