From df863397ae118acd3721593733c5a3c1eec45d38 Mon Sep 17 00:00:00 2001 From: frostming Date: Tue, 24 Dec 2019 10:34:19 +0800 Subject: [PATCH] Ignore dependency if not needed --- poetry/puzzle/provider.py | 14 +++++++++----- tests/puzzle/test_solver.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/poetry/puzzle/provider.py b/poetry/puzzle/provider.py index a077e28e91b..6c767943e14 100644 --- a/poetry/puzzle/provider.py +++ b/poetry/puzzle/provider.py @@ -671,13 +671,16 @@ def complete_package( raise CompatibilityError(*python_constraints) # Modifying dependencies as needed + clean_dependencies = [] for dep in dependencies: if not package.dependency.python_constraint.is_any(): - dep.transitive_python_versions = str( - dep.python_constraint.intersect( - package.dependency.python_constraint - ) + python_constraint_intersection = dep.python_constraint.intersect( + package.dependency.python_constraint ) + if python_constraint_intersection.is_empty(): + # This depencency is not needed under current python constraint. + continue + dep.transitive_python_versions = str(python_constraint_intersection) if (package.dependency.is_directory() or package.dependency.is_file()) and ( dep.is_directory() or dep.is_file() @@ -691,8 +694,9 @@ def complete_package( # TODO: Improve the way we set the correct relative path for dependencies dep._path = relative + clean_dependencies.append(dep) - package.requires = dependencies + package.requires = clean_dependencies return package diff --git a/tests/puzzle/test_solver.py b/tests/puzzle/test_solver.py index 6df7e97a697..d232dfb8c79 100644 --- a/tests/puzzle/test_solver.py +++ b/tests/puzzle/test_solver.py @@ -1887,3 +1887,19 @@ def test_solver_does_not_fail_with_locked_git_and_non_git_dependencies( {"job": "install", "package": git_package, "skipped": True}, ], ) + + +def test_ignore_python_constraint_no_overlap_dependencies(solver, repo, package): + pytest = get_package("demo", "1.0.0") + pytest.add_dependency("configparser", {"version": "^1.2.3", "python": "<3.2"}) + + package.add_dependency("demo", {"version": "^1.0.0", "python": "^3.6"}) + + repo.add_package(pytest) + repo.add_package(get_package("configparser", "1.2.3")) + + ops = solver.solve() + + check_solver_result( + ops, [{"job": "install", "package": pytest}], + )