Skip to content

Commit

Permalink
Merge pull request #258 from bstadlbauer/fix-aggregating-lock-specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusvniekerk authored Oct 9, 2022
2 parents d29fc5b + 606bc62 commit 2811502
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

## Developing

For the most up-to-date instructions see the github actions [test.yml workflow](./github/workflows.test.yml)
For the most up-to-date instructions see the github actions [test.yml workflow](./.github/workflows/test.yml)

1. Ensure conda and mamba are installed. Install [mambaforge](https://github.com/conda-forge/miniforge#mambaforge) if you're otherwise not sure which one to pick.
2. `mamba create -n conda-lock-dev pip pytest-cov pytest-xdist`
Expand Down
6 changes: 4 additions & 2 deletions conda_lock/src_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,10 @@ def aggregate_lock_specs(
):
key = (dep.manager, dep.name)
if key in unique_deps:
unique_deps[key].selectors |= dep.selectors
# overrides always win.
# Override existing, but merge selectors
previous_selectors = unique_deps[key].selectors
previous_selectors |= dep.selectors
dep.selectors = previous_selectors
unique_deps[key] = dep

dependencies = list(unique_deps.values())
Expand Down
50 changes: 50 additions & 0 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
HashModel,
LockedDependency,
LockSpecification,
Selectors,
VersionedDependency,
)
from conda_lock.src_parser.environment_yaml import parse_environment_file
Expand Down Expand Up @@ -353,6 +354,13 @@ def test_parse_meta_yaml_file(meta_yaml_environment: Path):
res = parse_meta_yaml_file(meta_yaml_environment, ["linux-64", "osx-64"])
specs = {dep.name: dep for dep in res.dependencies}
assert all(x in specs for x in ["python", "numpy"])
assert all(
dep.selectors
== Selectors(
platform=None
) # Platform will be set to None if all dependencies are the same
for dep in specs.values()
)
# Ensure that this dep specified by a python selector is ignored
assert "enum34" not in specs
# Ensure that this platform specific dep is included
Expand Down Expand Up @@ -707,6 +715,16 @@ def _make_spec(name: str, constraint: str = "*"):
)


def _make_dependency_with_platforms(
name: str, platforms: typing.List[str], constraint: str = "*"
):
return VersionedDependency(
name=name,
version=constraint,
selectors=Selectors(platform=platforms),
)


def test_aggregate_lock_specs():
"""Ensure that the way two specs combine when both specify channels is correct"""
base_spec = LockSpecification(
Expand Down Expand Up @@ -741,6 +759,38 @@ def test_aggregate_lock_specs():
assert actual.content_hash() == expected.content_hash()


def test_aggregate_lock_specs_multiple_platforms():
"""Ensure that plaforms are merged correctly"""
linux_spec = LockSpecification(
dependencies=[_make_dependency_with_platforms("python", ["linux-64"], "=3.7")],
channels=[Channel.from_string("conda-forge")],
platforms=["linux-64"],
sources=[Path("base-env.yml")],
)

osx_spec = LockSpecification(
dependencies=[_make_dependency_with_platforms("python", ["osx-64"], "=3.7")],
channels=[Channel.from_string("conda-forge")],
platforms=["osx-64"],
sources=[Path("base-env.yml")],
)

# NB: content hash explicitly does not depend on the source file names
actual = aggregate_lock_specs([linux_spec, osx_spec])
expected = LockSpecification(
dependencies=[
_make_dependency_with_platforms("python", ["linux-64", "osx-64"], "=3.7")
],
channels=[
Channel.from_string("conda-forge"),
],
platforms=["linux-64", "osx-64"],
sources=[],
)
assert actual.dict(exclude={"sources"}) == expected.dict(exclude={"sources"})
assert actual.content_hash() == expected.content_hash()


def test_aggregate_lock_specs_override_version():
base_spec = LockSpecification(
dependencies=[_make_spec("package", "=1.0")],
Expand Down

0 comments on commit 2811502

Please sign in to comment.