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

Fix resolution of packages with missing required extras #3035

Merged
merged 1 commit into from
Oct 1, 2020
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
16 changes: 6 additions & 10 deletions poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,23 +453,19 @@ def complete_package(
self.search_for_url(r)

optional_dependencies = []
activated_extras = []
for extra in package.dependency.extras:
if extra not in package.extras:
continue

activated_extras.append(extra)
optional_dependencies += [d.name for d in package.extras[extra]]

_dependencies = []

# If some extras/features were required, we need to
# add a special dependency representing the base package
# to the current package
if package.dependency.extras:
if activated_extras:
package = package.with_features(activated_extras)
for extra in package.dependency.extras:
if extra not in package.extras:
continue

optional_dependencies += [d.name for d in package.extras[extra]]

package = package.with_features(list(package.dependency.extras))
_dependencies.append(package.without_features().to_dependency())

for dep in requires:
Expand Down
7 changes: 1 addition & 6 deletions poetry/repositories/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@ def name(self):
def package(self, name, version, extras=None):
name = name.lower()

if extras is None:
extras = []

for package in self.packages:
if name == package.name and package.version.text == version:
package = package.with_features(extras)

return package
return package.clone()

def find_packages(self, dependency):
constraint = dependency.constraint
Expand Down
36 changes: 35 additions & 1 deletion tests/puzzle/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2435,7 +2435,6 @@ def test_solver_can_resolve_transitive_extras(solver, repo, package):
requests = get_package("requests", "2.24.0")
requests.add_dependency(Factory.create_dependency("certifi", ">=2017.4.17"))
dep = get_dependency("PyOpenSSL", ">=0.14")
dep.in_extras.append("security")
requests.add_dependency(
Factory.create_dependency("PyOpenSSL", {"version": ">=0.14", "optional": True})
)
Expand Down Expand Up @@ -2465,6 +2464,41 @@ def test_solver_can_resolve_transitive_extras(solver, repo, package):
)


def test_solver_can_resolve_for_packages_with_missing_extras(solver, repo, package):
package.add_dependency(
Factory.create_dependency(
"django-anymail", {"version": "^6.0", "extras": ["postmark"]}
)
)

django_anymail = get_package("django-anymail", "6.1.0")
django_anymail.add_dependency(Factory.create_dependency("django", ">=2.0"))
django_anymail.add_dependency(Factory.create_dependency("requests", ">=2.4.3"))
django_anymail.add_dependency(
Factory.create_dependency("boto3", {"version": "*", "optional": True})
)
django_anymail.extras["amazon_ses"] = [Factory.create_dependency("boto3", "*")]
django = get_package("django", "2.2.0")
boto3 = get_package("boto3", "1.0.0")
requests = get_package("requests", "2.24.0")

repo.add_package(django_anymail)
repo.add_package(django)
repo.add_package(boto3)
repo.add_package(requests)

ops = solver.solve()

check_solver_result(
ops,
[
{"job": "install", "package": django},
{"job": "install", "package": requests},
{"job": "install", "package": django_anymail},
],
)


def test_solver_can_resolve_python_restricted_package_dependencies(
solver, repo, package, locked
):
Expand Down