Skip to content

Commit 67c1e1b

Browse files
committed
do not remove --dev, revoke deprecation
1 parent 3351774 commit 67c1e1b

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

docs/cli.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ about dependency groups.
448448
### Options
449449

450450
* `--group (-G)`: The group to add the dependency to.
451+
* `--dev (-D)`: Add package as development dependency. (shortcut for `-G dev`)
451452
* `--editable (-e)`: Add vcs/path dependencies as editable.
452453
* `--extras (-E)`: Extras to activate for the dependency. (multiple values allowed)
453454
* `--optional`: Add as an optional dependency to an extra.
@@ -480,6 +481,7 @@ about dependency groups.
480481
### Options
481482

482483
* `--group (-G)`: The group to remove the dependency from.
484+
* `--dev (-D)`: Removes a package from the development dependencies. (shortcut for `-G dev`)
483485
* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose).
484486
* `--lock`: Do not perform operations (only update the lockfile).
485487

src/poetry/console/commands/add.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class AddCommand(InstallerCommand, InitCommand):
4040
flag=False,
4141
default=MAIN_GROUP,
4242
),
43+
option(
44+
"dev",
45+
"D",
46+
"Add as a development dependency. (shortcut for '-G dev')",
47+
),
4348
option("editable", "e", "Add vcs/path dependencies as editable."),
4449
option(
4550
"extras",
@@ -122,7 +127,10 @@ def handle(self) -> int:
122127
from poetry.factory import Factory
123128

124129
packages = self.argument("name")
125-
group = self.option("group", self.default_group or MAIN_GROUP)
130+
if self.option("dev"):
131+
group = "dev"
132+
else:
133+
group = self.option("group", self.default_group or MAIN_GROUP)
126134

127135
if self.option("extras") and len(packages) > 1:
128136
raise ValueError(

src/poetry/console/commands/remove.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class RemoveCommand(InstallerCommand):
2828
]
2929
options: ClassVar[list[Option]] = [
3030
option("group", "G", "The group to remove the dependency from.", flag=False),
31+
option(
32+
"dev",
33+
"D",
34+
"Remove a package from the development dependencies."
35+
" (shortcut for '-G dev')",
36+
),
3137
option(
3238
"dry-run",
3339
None,
@@ -49,7 +55,11 @@ class RemoveCommand(InstallerCommand):
4955

5056
def handle(self) -> int:
5157
packages = self.argument("packages")
52-
group = self.option("group", self.default_group)
58+
59+
if self.option("dev"):
60+
group = "dev"
61+
else:
62+
group = self.option("group", self.default_group)
5363

5464
content: dict[str, Any] = self.poetry.file.read()
5565
project_content = content.get("project", {})

tests/console/commands/test_add.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,35 @@ def test_add_creating_poetry_section_does_not_remove_existing_tools(
10911091
assert pyproject["tool"]["foo"]["key"] == "value"
10921092

10931093

1094+
def test_add_to_dev_section(app: PoetryTestApplication, tester: CommandTester) -> None:
1095+
tester.execute("cachy --dev")
1096+
1097+
expected = """\
1098+
Using version ^0.2.0 for cachy
1099+
1100+
Updating dependencies
1101+
Resolving dependencies...
1102+
1103+
Package operations: 2 installs, 0 updates, 0 removals
1104+
1105+
- Installing msgpack-python (0.5.6)
1106+
- Installing cachy (0.2.0)
1107+
1108+
Writing lock file
1109+
"""
1110+
1111+
assert tester.io.fetch_error() == ""
1112+
assert tester.io.fetch_output() == expected
1113+
assert isinstance(tester.command, InstallerCommand)
1114+
assert tester.command.installer.executor.installations_count == 2
1115+
1116+
pyproject: dict[str, Any] = app.poetry.file.read()
1117+
content = pyproject["tool"]["poetry"]
1118+
1119+
assert "cachy" in content["group"]["dev"]["dependencies"]
1120+
assert content["group"]["dev"]["dependencies"]["cachy"] == "^0.2.0"
1121+
1122+
10941123
def test_add_should_not_select_prereleases(
10951124
app: PoetryTestApplication, tester: CommandTester
10961125
) -> None:

0 commit comments

Comments
 (0)