Skip to content

Commit

Permalink
Fix adding requests with the security extra (#1439)
Browse files Browse the repository at this point in the history
Using poetry from master/develop branches or any recent alpha/beta release,
you can't add the requests package with the security extra.
The requests package requires the idna twice
(as a main dependency and as an optional one) and this case wasn't handled
properly in Locker._dump_package function.
These changes make the _dump_package ensures that
all elements of the constraints list have the same type
in order to make them renderable as TOML.
  • Loading branch information
Jamim authored and sdispater committed Oct 11, 2019
1 parent 8a7764f commit d1f9842
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,6 @@ def _dump_package(self, package): # type: (poetry.packages.Package) -> dict

if dependency.pretty_name not in dependencies:
dependencies[dependency.pretty_name] = []
else:
# Ensure we don't have mixed types in the lock file
for i, spec in enumerate(dependencies[dependency.pretty_name]):
if not isinstance(spec, dict):
dependencies[dependency.pretty_name][i] = {"version": spec}

constraint = {"version": str(dependency.pretty_constraint)}

Expand All @@ -235,10 +230,15 @@ def _dump_package(self, package): # type: (poetry.packages.Package) -> dict
if not dependency.python_constraint.is_any():
constraint["python"] = str(dependency.python_constraint)

if len(constraint) == 1:
dependencies[dependency.pretty_name].append(constraint["version"])
else:
dependencies[dependency.pretty_name].append(constraint)
dependencies[dependency.pretty_name].append(constraint)

# All the constraints should have the same type,
# but we want to simplify them if it's possible
for dependency, constraints in tuple(dependencies.items()):
if all(len(constraint) == 1 for constraint in constraints):
dependencies[dependency] = [
constraint["version"] for constraint in constraints
]

data = {
"name": package.pretty_name,
Expand Down

0 comments on commit d1f9842

Please sign in to comment.