Commit d1f9842f by Aliaksei Urbanski Committed by Sébastien Eustace

Fix adding requests with the security extra (#1439)

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.
parent 8a7764f5
...@@ -218,11 +218,6 @@ class Locker(object): ...@@ -218,11 +218,6 @@ class Locker(object):
if dependency.pretty_name not in dependencies: if dependency.pretty_name not in dependencies:
dependencies[dependency.pretty_name] = [] 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)} constraint = {"version": str(dependency.pretty_constraint)}
...@@ -235,10 +230,15 @@ class Locker(object): ...@@ -235,10 +230,15 @@ class Locker(object):
if not dependency.python_constraint.is_any(): if not dependency.python_constraint.is_any():
constraint["python"] = str(dependency.python_constraint) constraint["python"] = str(dependency.python_constraint)
if len(constraint) == 1: dependencies[dependency.pretty_name].append(constraint)
dependencies[dependency.pretty_name].append(constraint["version"])
else: # All the constraints should have the same type,
dependencies[dependency.pretty_name].append(constraint) # 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 = { data = {
"name": package.pretty_name, "name": package.pretty_name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment