From 5dab851d9b22b544ddcf7208e53956ffe4d90ce7 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 30 Apr 2023 13:19:35 +0100 Subject: [PATCH] parse extras correctly at 'poetry add' (#7836) --- src/poetry/console/commands/add.py | 2 +- tests/console/commands/test_add.py | 52 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/poetry/console/commands/add.py b/src/poetry/console/commands/add.py index f8c82c18c29..3815a2e1292 100644 --- a/src/poetry/console/commands/add.py +++ b/src/poetry/console/commands/add.py @@ -192,7 +192,7 @@ def handle(self) -> int: for extra in self.option("extras"): extras += extra.split() - constraint["extras"] = self.option("extras") + constraint["extras"] = extras if self.option("editable"): if "git" in _constraint or "path" in _constraint: diff --git a/tests/console/commands/test_add.py b/tests/console/commands/test_add.py index cb5a0c7ea34..23d7e2ee8dc 100644 --- a/tests/console/commands/test_add.py +++ b/tests/console/commands/test_add.py @@ -1415,3 +1415,55 @@ def test_add_with_path_dependency_no_loopiness( with pytest.raises(SolverProblemError): tester.execute("requests") + + +def test_add_extras_are_parsed_and_included( + app: PoetryTestApplication, + repo: TestRepository, + tester: CommandTester, +) -> None: + msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6", optional=True) + redis_dep = get_dependency("redis", ">=3.3.6 <4.0.0", optional=True) + + cachy = get_package("cachy", "0.2.0") + cachy.add_dependency(msgpack_dep) + cachy.add_dependency(redis_dep) + cachy.extras = { + canonicalize_name("redis"): [redis_dep], + canonicalize_name("msgpack"): [msgpack_dep], + } + repo.add_package(cachy) + + msgpack = get_package("msgpack-python", "0.5.1") + repo.add_package(msgpack) + + redis = get_package("redis", "3.4.0") + repo.add_package(redis) + + tester.execute('cachy --extras "redis msgpack"') + + expected = """\ +Using version ^0.2.0 for cachy + +Updating dependencies +Resolving dependencies... + +Package operations: 3 installs, 0 updates, 0 removals + + • Installing msgpack-python (0.5.1) + • Installing redis (3.4.0) + • Installing cachy (0.2.0) + +Writing lock file +""" + + assert tester.io.fetch_output() == expected + + pyproject: dict[str, Any] = app.poetry.file.read() + content = pyproject["tool"]["poetry"] + + assert "cachy" in content["dependencies"] + assert content["dependencies"]["cachy"] == { + "version": "^0.2.0", + "extras": ["redis", "msgpack"], + }