Skip to content

Commit

Permalink
Merge pull request #181 from mariusvniekerk/consistent-ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusvniekerk authored Mar 24, 2022
2 parents 06e24cd + 70642a8 commit a22ce5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion conda_lock/src_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ def __ror__(self, other: "Optional[Lockfile]") -> "Lockfile":
else:
package.append(ours[key])

# Resort the conda packages topologically
final_package = self._toposort(package)
return Lockfile(package=final_package, metadata=other.metadata | self.metadata)

def toposort_inplace(self) -> None:
self.package = self._toposort(self.package)

@staticmethod
def _toposort(
package: List[LockedDependency], update: bool = False
) -> List[LockedDependency]:
platforms = {d.platform for d in package}

# Resort the conda packages topologically
Expand Down Expand Up @@ -209,7 +220,7 @@ def __ror__(self, other: "Optional[Lockfile]") -> "Lockfile":

final_package.append(dep)

return Lockfile(package=final_package, metadata=other.metadata | self.metadata)
return final_package


class LockSpecification(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions conda_lock/src_parser/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def parse_conda_lock_file(
def write_conda_lock_file(
content: Lockfile, path: pathlib.Path, include_help_text: bool = True
) -> None:
content.toposort_inplace()
with path.open("w") as f:
if include_help_text:
categories = set(p.category for p in content.package)
Expand Down

0 comments on commit a22ce5a

Please sign in to comment.