Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent channel/dependency reordering when rendering the environment #203

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
CHANGELOG
=========

UNRELEASED
----------

- Dependency order is no longer sorted automatically, instead the order is preserved as they are defined in the ``*.devenv.yml`` files.
Usually this would not matter, but it is important for ``pip`` dependencies which declare development installations, as it is important
that those happen in the specified order.
prusse-martin marked this conversation as resolved.
Show resolved Hide resolved


3.2.1 (2024-01-03)
------------------

Expand Down
10 changes: 5 additions & 5 deletions src/conda_devenv/devenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,15 @@ def merge_dependencies_version_specifications(
else:
raise UsageError(f"Only strings and dicts are supported, got: {dep!r}")

result = set()
# keep the order of dependencies
result: dict[str, Any] = collections.OrderedDict()
for dep_name, dep_version_matchers in new_dependencies.items():
if len(dep_version_matchers) > 0:
result.add(dep_name + " " + ",".join(dep_version_matchers))
result[dep_name + " " + ",".join(dep_version_matchers)] = None
else:
result.add(dep_name)
result[dep_name] = None

new_dict_dependencies = sorted(new_dict_dependencies, key=lambda x: list(x.keys()))
yaml_dict[key_to_merge] = sorted(result) + new_dict_dependencies
yaml_dict[key_to_merge] = list(result.keys()) + new_dict_dependencies


@dataclass(frozen=True)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_load_yaml_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ def test_downstream_overrides_platforms(tmp_path) -> None:
}


def test_load_yaml_dict_dependency_order(datadir) -> None:
"""
Make sure the order of channels and pip dependencies is preserved
"""
conda_yaml_dict = load_yaml_dict(datadir / "deps_order.yml")
channels = conda_yaml_dict["channels"]
assert channels == ["pytorch", "nvidia", "conda-forge", "bioconda"]
pip_dependencies = conda_yaml_dict["dependencies"][3]
assert pip_dependencies["pip"] == ["-e c-package", "-e b-package", "-e D-package"]


class TestConstraints:
def test_no_constraints(self) -> None:
data = {"dependencies": ["attrs >19", "boltons"]}
Expand Down
16 changes: 16 additions & 0 deletions tests/test_load_yaml_dict/deps_order.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: test-env

channels:
- pytorch
- nvidia
- conda-forge
- bioconda

dependencies:
- pytorch
- numpy
- scikit-image
- pip:
- "-e c-package"
- "-e b-package"
- "-e D-package"
Loading