Skip to content

Commit

Permalink
solver: fix special case where a direct origin dependency without ext…
Browse files Browse the repository at this point in the history
…ras is requested by the project and the same dependency with extras is requested by another dependency
  • Loading branch information
radoering authored and neersighted committed Jul 13, 2022
1 parent 92dde5b commit bd9c5c8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
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

0 comments on commit bd9c5c8

Please sign in to comment.