Skip to content

Commit

Permalink
Merge pull request python-poetry#3035 from python-poetry/fix-handling…
Browse files Browse the repository at this point in the history
…-of-missing-extras

Fix resolution of packages with missing required extras
  • Loading branch information
sdispater authored Oct 1, 2020
2 parents 1b07b2b + b3dba51 commit 9408eff
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
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

0 comments on commit 9408eff

Please sign in to comment.