mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-09-11 14:35:30 +03:00
fix(v1/pip): bug in fetchPipMetadata when multiple roots are requested
So far, whenever multiple roots are requested, only the last one was respected for the lock file Now all roots are merged into the `default` extra
This commit is contained in:
parent
0511fe863d
commit
2ee5aaebd8
@ -186,6 +186,10 @@ def lock_file_from_report(report):
|
||||
# targets to lock dependencies for, i.e. env markers like "dev" or "tests"
|
||||
targets = dict()
|
||||
|
||||
# ensure at least one package is requested
|
||||
if not any(install.get("requested", False) for install in report["install"]):
|
||||
raise Exception("Cannot determine roots, nothing requested")
|
||||
|
||||
# iterate over all packages pip installed to find roots
|
||||
# of the tree and gather basic information, such as urls
|
||||
for install in report["install"]:
|
||||
@ -209,7 +213,10 @@ def lock_file_from_report(report):
|
||||
evaluate_requirements(
|
||||
env, requirements, dependencies, root_name, extras, list()
|
||||
)
|
||||
targets[extra] = dependencies
|
||||
if extra not in targets:
|
||||
targets[extra] = dependencies
|
||||
else:
|
||||
targets[extra].update(dependencies)
|
||||
|
||||
# iterate over targets to deduplicate dependencies already in the default set
|
||||
# with the same indirect deps
|
||||
|
@ -2,6 +2,24 @@ import pytest
|
||||
import lock_file_from_report as l
|
||||
|
||||
|
||||
def test_nothing_requested():
|
||||
report = dict(
|
||||
environment=dict(),
|
||||
install=[
|
||||
dict(
|
||||
metadata=dict(
|
||||
name="test",
|
||||
version="0.0.0",
|
||||
),
|
||||
download_info=dict(url="https://example.com"),
|
||||
)
|
||||
],
|
||||
)
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
l.lock_file_from_report(report)
|
||||
assert "Cannot determine roots" in exc_info.value
|
||||
|
||||
|
||||
def test_simple():
|
||||
report = dict(
|
||||
environment=dict(),
|
||||
@ -31,3 +49,48 @@ def test_simple():
|
||||
),
|
||||
)
|
||||
assert l.lock_file_from_report(report) == expected
|
||||
|
||||
|
||||
def test_multiple_requested():
|
||||
report = dict(
|
||||
environment=dict(),
|
||||
install=[
|
||||
dict(
|
||||
requested=True,
|
||||
metadata=dict(
|
||||
name="foo",
|
||||
version="0.0.0",
|
||||
),
|
||||
download_info=dict(url="https://example.com"),
|
||||
),
|
||||
dict(
|
||||
requested=True,
|
||||
metadata=dict(
|
||||
name="bar",
|
||||
version="0.0.0",
|
||||
),
|
||||
download_info=dict(url="https://example.com"),
|
||||
),
|
||||
],
|
||||
)
|
||||
expected = dict(
|
||||
sources=dict(
|
||||
foo=dict(
|
||||
sha256=None,
|
||||
url="https://example.com",
|
||||
version="0.0.0",
|
||||
),
|
||||
bar=dict(
|
||||
sha256=None,
|
||||
url="https://example.com",
|
||||
version="0.0.0",
|
||||
),
|
||||
),
|
||||
targets=dict(
|
||||
default=dict(
|
||||
foo=[],
|
||||
bar=[],
|
||||
),
|
||||
),
|
||||
)
|
||||
assert l.lock_file_from_report(report) == expected
|
||||
|
Loading…
Reference in New Issue
Block a user