From b42fa14bcc36f0abee077f84ac22cd89e0b4dce6 Mon Sep 17 00:00:00 2001 From: Jeffrey Seifried Date: Wed, 13 Mar 2024 11:38:15 -0700 Subject: [PATCH 1/2] Switch the order of LockMeta's being merged so that `other` takes precedence over `self` --- conda_lock/lockfile/v2prelim/models.py | 2 +- tests/test_conda_lock.py | 27 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/conda_lock/lockfile/v2prelim/models.py b/conda_lock/lockfile/v2prelim/models.py index 8fbce6f53..dffafe142 100644 --- a/conda_lock/lockfile/v2prelim/models.py +++ b/conda_lock/lockfile/v2prelim/models.py @@ -65,7 +65,7 @@ def merge(self, other: "Optional[Lockfile]") -> "Lockfile": # Resort the conda packages topologically final_package = self._toposort(package) - return Lockfile(package=final_package, metadata=other.metadata | self.metadata) + return Lockfile(package=final_package, metadata=self.metadata | other.metadata) def toposort_inplace(self) -> None: self.package = self._toposort(self.package) diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index e70a53e67..500dc260c 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -2729,3 +2729,30 @@ def test_pip_full_whl_url( typing_extensions_dep.hash.sha256 == "8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0" ) + + +def test_when_merging_lockfiles_content_hashes_are_updated( + conda_exe: str, + monkeypatch: "pytest.MonkeyPatch", + tmp_path: Path, +): + work_path = clone_test_dir(name="test-update", tmp_path=tmp_path) + monkeypatch.chdir(work_path) + run_lock( + environment_files=[work_path / "environment-preupdate.yml"], + conda_exe=str(conda_exe), + platforms=["linux-64"], + ) + + def get_content_hashes_for_lock_file(lock_file: Path) -> dict[str, str]: + lock_file_dict = yaml.safe_load(lock_file.read_text()) + return lock_file_dict["metadata"]["content_hash"] + + preupdate_hashes = get_content_hashes_for_lock_file(work_path / "conda-lock.yml") + run_lock( + environment_files=[work_path / "environment-postupdate.yml"], + conda_exe=str(conda_exe), + platforms=["linux-64"], + ) + postupdate_hashes = get_content_hashes_for_lock_file(work_path / "conda-lock.yml") + assert preupdate_hashes != postupdate_hashes From 55747d20abae9723e9361c6311dbcf6742675cf4 Mon Sep 17 00:00:00 2001 From: Jeffrey Seifried Date: Wed, 13 Mar 2024 12:08:27 -0700 Subject: [PATCH 2/2] Use typing.Dict instead of dict --- tests/test_conda_lock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index 500dc260c..a38edb67b 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -2744,7 +2744,7 @@ def test_when_merging_lockfiles_content_hashes_are_updated( platforms=["linux-64"], ) - def get_content_hashes_for_lock_file(lock_file: Path) -> dict[str, str]: + def get_content_hashes_for_lock_file(lock_file: Path) -> typing.Dict[str, str]: lock_file_dict = yaml.safe_load(lock_file.read_text()) return lock_file_dict["metadata"]["content_hash"]