Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore dependency if not needed #1789

Merged
merged 1 commit into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}],
)