Skip to content

Commit

Permalink
Ignore dependency if not needed (#1789)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored and sdispater committed Dec 26, 2019
1 parent 299a885 commit 9d749a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
14 changes: 9 additions & 5 deletions poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down
16 changes: 16 additions & 0 deletions tests/puzzle/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}],
)

0 comments on commit 9d749a4

Please sign in to comment.