Skip to content

Commit

Permalink
Consider all overwrites and not only the overwrites of one package wh…
Browse files Browse the repository at this point in the history
…en building the marker intersection
  • Loading branch information
radoering authored and abn committed Apr 26, 2022
1 parent 94a60ca commit ec9c056
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,9 @@ def fmt_warning(d: Dependency) -> str:
dep_other.set_constraint(
dep_other.constraint.intersect(dep_any.constraint)
)
else:
# if there is no any marker dependency,
elif not inverted_marker.is_empty():
# if there is no any marker dependency
# and the inverted marker is not empty,
# a dependency with the inverted union of all markers is required
# in order to not miss other dependencies later, for instance:
# - foo (1.0) ; python == 3.7
Expand All @@ -655,10 +656,11 @@ def fmt_warning(d: Dependency) -> str:

overrides = []
overrides_marker_intersection = AnyMarker()
for _dep in self._overrides.get(package, {}).values():
overrides_marker_intersection = overrides_marker_intersection.intersect(
_dep.marker
)
for dep_overrides in self._overrides.values():
for _dep in dep_overrides.values():
overrides_marker_intersection = (
overrides_marker_intersection.intersect(_dep.marker)
)
for _dep in _deps:
if not overrides_marker_intersection.intersect(_dep.marker).is_empty():
current_overrides = self._overrides.copy()
Expand Down
43 changes: 43 additions & 0 deletions tests/puzzle/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,49 @@ def test_solver_duplicate_dependencies_ignore_overrides_with_empty_marker_inters
)


def test_solver_duplicate_dependencies_ignore_overrides_with_empty_marker_intersection2(
solver: Solver, repo: Repository, package: Package
):
"""
Empty intersection between top level dependency and transient dependency.
"""
package.add_dependency(Factory.create_dependency("A", {"version": "1.0"}))
package.add_dependency(
Factory.create_dependency("B", {"version": ">=2.0", "python": ">=3.7"})
)
package.add_dependency(
Factory.create_dependency("B", {"version": "*", "python": "<3.7"})
)

package_a10 = get_package("A", "1.0")
package_a10.add_dependency(
Factory.create_dependency("B", {"version": ">=2.0", "python": ">=3.7"})
)
package_a10.add_dependency(
Factory.create_dependency("B", {"version": "*", "python": "<3.7"})
)

package_b10 = get_package("B", "1.0")
package_b10.python_versions = "<3.7"
package_b20 = get_package("B", "2.0")
package_b20.python_versions = ">=3.7"

repo.add_package(package_a10)
repo.add_package(package_b10)
repo.add_package(package_b20)

transaction = solver.solve()

check_solver_result(
transaction,
[
{"job": "install", "package": package_b10},
{"job": "install", "package": package_b20},
{"job": "install", "package": package_a10},
],
)


def test_solver_duplicate_dependencies_sub_dependencies(
solver: Solver, repo: Repository, package: ProjectPackage
):
Expand Down

0 comments on commit ec9c056

Please sign in to comment.