Skip to content

Commit

Permalink
do not remove --dev, revoke deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Oct 12, 2024
1 parent 742a786 commit 8839ced
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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).

Expand Down
10 changes: 9 additions & 1 deletion src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 11 additions & 1 deletion src/poetry/console/commands/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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", {})
Expand Down
29 changes: 29 additions & 0 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8839ced

Please sign in to comment.