Skip to content

Commit

Permalink
Prevent channel/dependency reordering when rendering the environment (#…
Browse files Browse the repository at this point in the history
…203)

Co-authored-by: Bruno Oliveira <[email protected]>
Co-authored-by: Martin Prüsse <[email protected]>
  • Loading branch information
3 people authored Feb 21, 2024
1 parent 3610197 commit 55276d6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
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.


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"

0 comments on commit 55276d6

Please sign in to comment.