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

Alphabetize the lockfile #524

Merged
merged 8 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
is_micromamba,
)
from conda_lock.lockfile import (
UnknownLockfileVersion,
parse_conda_lock_file,
write_conda_lock_file,
)
Expand Down
8 changes: 6 additions & 2 deletions conda_lock/lockfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,15 @@ def parse_conda_lock_file(path: pathlib.Path) -> Lockfile:
content = yaml.safe_load(f)
version = content.pop("version", None)
if version == 1:
return lockfile_v1_to_v2(LockfileV1.parse_obj(content))
lockfile = lockfile_v1_to_v2(LockfileV1.parse_obj(content))
elif version == 2:
lockfile = Lockfile.parse_obj(content)
elif version is None:
raise MissingLockfileVersion(f"{path} is missing a version")
else:
raise UnknownLockfileVersion(f"{path} has unknown version {version}")
lockfile.toposort_inplace()
return lockfile


def write_conda_lock_file(
Expand All @@ -155,7 +159,7 @@ def write_conda_lock_file(
metadata_choices: Optional[Collection[MetadataOption]],
include_help_text: bool = True,
) -> None:
content.toposort_inplace()
content.alphasort_inplace()
with path.open("w") as f:
if include_help_text:
categories = set(p.category for p in content.package)
Expand Down
3 changes: 3 additions & 0 deletions conda_lock/lockfile/v2prelim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def __ror__(self, other: "Optional[Lockfile]") -> "Lockfile":
def toposort_inplace(self) -> None:
self.package = self._toposort(self.package)

def alphasort_inplace(self) -> None:
self.package.sort(key=lambda d: d.key())

@staticmethod
def _toposort(
package: List[LockedDependency], update: bool = False
Expand Down
Loading