Skip to content

Commit

Permalink
Merge pull request #618 from jeffseif/jeffseif/update-content-hashes-…
Browse files Browse the repository at this point in the history
…inplace

fix: Ensure that content hashes are updated for an existing lock file when re-locking
  • Loading branch information
maresb committed Mar 13, 2024
2 parents 4448144 + 55747d2 commit ba0da39
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conda_lock/lockfile/v2prelim/models.py
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_conda_lock.py
Expand Up @@ -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) -> typing.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

0 comments on commit ba0da39

Please sign in to comment.