Skip to content

Commit

Permalink
Ignore dependency if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Dec 24, 2019
1 parent 945ca1d commit 685f9a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 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
18 changes: 17 additions & 1 deletion tests/puzzle/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from tests.helpers import get_dependency
from tests.helpers import get_package
from tests.repositories.test_legacy_repository import (
MockRepository as MockLegacyRepository,
MockRepository as MockLegacyRepository
)
from tests.repositories.test_pypi_repository import MockRepository as MockPyPIRepository

Expand Down 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 685f9a7

Please sign in to comment.