From 9d7e91f0486c2b1805cbffe0202db4a1f0a3af64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Fri, 3 Jul 2020 11:39:52 +0200 Subject: [PATCH] Fix dependency overrides for packages with multiple duplicate dependencies --- poetry/puzzle/provider.py | 2 +- tests/puzzle/test_solver.py | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/poetry/puzzle/provider.py b/poetry/puzzle/provider.py index 00c70689221..162c6602335 100644 --- a/poetry/puzzle/provider.py +++ b/poetry/puzzle/provider.py @@ -646,7 +646,7 @@ def complete_package( overrides = [] for _dep in _deps: current_overrides = self._overrides.copy() - package_overrides = current_overrides.get(package, {}) + package_overrides = current_overrides.get(package, {}).copy() package_overrides.update({_dep.name: _dep}) current_overrides.update({package: package_overrides}) overrides.append(current_overrides) diff --git a/tests/puzzle/test_solver.py b/tests/puzzle/test_solver.py index 0e1202964e8..d1b9f96c332 100644 --- a/tests/puzzle/test_solver.py +++ b/tests/puzzle/test_solver.py @@ -2003,3 +2003,43 @@ def test_solver_should_not_update_same_version_packages_if_installed_has_no_sour check_solver_result( ops, [{"job": "install", "package": foo, "skipped": True}], ) + + +def test_solver_should_resolve_all_versions_for_multiple_duplicate_dependencies( + solver, repo, package +): + package.python_versions = "~2.7 || ^3.5" + package.add_dependency( + "A", {"version": "^1.0", "markers": "python_version < '3.5'"} + ) + package.add_dependency( + "A", {"version": "^2.0", "markers": "python_version >= '3.5'"} + ) + package.add_dependency( + "B", {"version": "^3.0", "markers": "python_version < '3.5'"} + ) + package.add_dependency( + "B", {"version": "^4.0", "markers": "python_version >= '3.5'"} + ) + + package_a10 = get_package("A", "1.0.0") + package_a20 = get_package("A", "2.0.0") + package_b30 = get_package("B", "3.0.0") + package_b40 = get_package("B", "4.0.0") + + repo.add_package(package_a10) + repo.add_package(package_a20) + repo.add_package(package_b30) + repo.add_package(package_b40) + + ops = solver.solve() + + check_solver_result( + ops, + [ + {"job": "install", "package": package_a10}, + {"job": "install", "package": package_a20}, + {"job": "install", "package": package_b30}, + {"job": "install", "package": package_b40}, + ], + )