From 908cd2c7fda6813518604b8f7cf31059b3e90b58 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Fri, 24 Nov 2023 15:35:29 +0100 Subject: [PATCH 1/3] Remove unused "update" argument of _toposort --- conda_lock/lockfile/v2prelim/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/conda_lock/lockfile/v2prelim/models.py b/conda_lock/lockfile/v2prelim/models.py index 1f8ea384..706edc3b 100644 --- a/conda_lock/lockfile/v2prelim/models.py +++ b/conda_lock/lockfile/v2prelim/models.py @@ -84,9 +84,7 @@ def filter_virtual_packages_inplace(self) -> None: ] @staticmethod - def _toposort( - package: List[LockedDependency], update: bool = False - ) -> List[LockedDependency]: + def _toposort(package: List[LockedDependency]) -> List[LockedDependency]: platforms = {d.platform for d in package} # Resort the conda packages topologically From 051b7ae5031cba2595c39193e560899852812dba Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Fri, 24 Nov 2023 16:03:26 +0100 Subject: [PATCH 2/3] Filter virtual packages separately from toposort. Otherwise it's logically confusing, and it led to #556 --- conda_lock/conda_lock.py | 1 + conda_lock/lockfile/v2prelim/models.py | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/conda_lock/conda_lock.py b/conda_lock/conda_lock.py index e7891d8e..5ac4d5d7 100644 --- a/conda_lock/conda_lock.py +++ b/conda_lock/conda_lock.py @@ -609,6 +609,7 @@ def render_lockfile_for_platform( # noqa: C901 # ensure consistent ordering of generated file lockfile.toposort_inplace() + lockfile.filter_virtual_packages_inplace() for p in lockfile.package: if p.platform == platform and p.category in categories: diff --git a/conda_lock/lockfile/v2prelim/models.py b/conda_lock/lockfile/v2prelim/models.py index 706edc3b..037afd15 100644 --- a/conda_lock/lockfile/v2prelim/models.py +++ b/conda_lock/lockfile/v2prelim/models.py @@ -118,10 +118,6 @@ def _toposort(package: List[LockedDependency]) -> List[LockedDependency]: continue if dep.manager != manager: continue - # skip virtual packages - if dep.manager == "conda" and dep.name.startswith("__"): - continue - final_package.append(dep) return final_package From 41ae11fc39826088f5c772546161950589189ab3 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Fri, 24 Nov 2023 16:16:35 +0100 Subject: [PATCH 3/3] Replace __or__ method with merge() While __or__ is fancy, using "merge" is more self-explanatory, and it makes introspection easier. --- conda_lock/conda_lock.py | 2 +- conda_lock/lockfile/v2prelim/models.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/conda_lock/conda_lock.py b/conda_lock/conda_lock.py index 5ac4d5d7..631db834 100644 --- a/conda_lock/conda_lock.py +++ b/conda_lock/conda_lock.py @@ -414,7 +414,7 @@ def make_lock_files( # noqa: C901 deep=True, update={"package": packages_not_to_lock}, ) - new_lock_content = lock_content_to_persist | fresh_lock_content + new_lock_content = lock_content_to_persist.merge(fresh_lock_content) if "lock" in kinds: write_conda_lock_file( diff --git a/conda_lock/lockfile/v2prelim/models.py b/conda_lock/lockfile/v2prelim/models.py index 037afd15..8fbce6f5 100644 --- a/conda_lock/lockfile/v2prelim/models.py +++ b/conda_lock/lockfile/v2prelim/models.py @@ -39,10 +39,7 @@ class Lockfile(StrictModel): package: List[LockedDependency] metadata: LockMeta - def __or__(self, other: "Lockfile") -> "Lockfile": - return other.__ror__(self) - - def __ror__(self, other: "Optional[Lockfile]") -> "Lockfile": + def merge(self, other: "Optional[Lockfile]") -> "Lockfile": """ merge self into other """