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

solver: fix special case where a direct origin dependency without extras ... #5770

Merged
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
11 changes: 10 additions & 1 deletion src/poetry/mixology/partial_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

from poetry.mixology.assignment import Assignment
from poetry.mixology.set_relation import SetRelation
from poetry.mixology.term import Term


if TYPE_CHECKING:
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package

from poetry.mixology.incompatibility import Incompatibility
from poetry.mixology.term import Term


class PartialSolution:
Expand Down Expand Up @@ -146,6 +146,15 @@ def _register(self, assignment: Assignment) -> None:
"""
name = assignment.dependency.complete_name
old_positive = self._positive.get(name)
if old_positive is None and assignment.dependency.features:
old_positive_without_features = self._positive.get(
assignment.dependency.name
)
if old_positive_without_features is not None:
dep = old_positive_without_features.dependency.with_features(
assignment.dependency.features
)
old_positive = Term(dep, is_positive=True)
if old_positive is not None:
value = old_positive.intersect(assignment)
assert value is not None
Expand Down
52 changes: 52 additions & 0 deletions tests/puzzle/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3539,3 +3539,55 @@ def test_solver_keeps_multiple_locked_dependencies_for_same_package(
{"job": "install", "package": a12},
],
)


def test_solver_direct_origin_dependency_with_extras_requested_by_other_package(
solver: Solver, repo: Repository, package: ProjectPackage
):
"""
Another package requires the same dependency with extras that is required
by the project as direct origin dependency without any extras.
"""
pendulum = get_package("pendulum", "2.0.3") # required by demo
cleo = get_package("cleo", "1.0.0") # required by demo[foo]
demo_foo = get_package("demo-foo", "1.2.3")
demo_foo.add_dependency(
Factory.create_dependency("demo", {"version": ">=0.1", "extras": ["foo"]})
)
repo.add_package(demo_foo)
repo.add_package(pendulum)
repo.add_package(cleo)

path = (
Path(__file__).parent.parent
/ "fixtures"
/ "git"
/ "github.com"
/ "demo"
/ "demo"
).as_posix()

# project requires path dependency of demo while demo-foo requires demo[foo]
package.add_dependency(Factory.create_dependency("demo", {"path": path}))
package.add_dependency(Factory.create_dependency("demo-foo", "^1.2.3"))

transaction = solver.solve()

demo = Package("demo", "0.1.2", source_type="directory", source_url=path)

ops = check_solver_result(
transaction,
[
{"job": "install", "package": cleo},
{"job": "install", "package": pendulum},
{"job": "install", "package": demo},
{"job": "install", "package": demo_foo},
],
)

op = ops[2]

assert op.package.name == "demo"
assert op.package.version.text == "0.1.2"
assert op.package.source_type == "directory"
assert op.package.source_url == path