Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse extras correctly at 'poetry add' #7836

Merged
merged 1 commit into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
52 changes: 52 additions & 0 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}