Skip to content

Commit

Permalink
refactor: Sort inventories
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Aug 28, 2023
1 parent 228fb73 commit 9371e9f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/mkdocstrings/inventory.py
Expand Up @@ -135,7 +135,10 @@ def format_sphinx(self) -> bytes:
.encode("utf8")
)

lines = [item.format_sphinx().encode("utf8") for item in self.values()]
lines = [
item.format_sphinx().encode("utf8")
for item in sorted(self.values(), key=lambda item: (item.domain, item.name))
]
return header + zlib.compress(b"\n".join(lines) + b"\n", 9)

@classmethod
Expand All @@ -155,4 +158,4 @@ def parse_sphinx(cls, in_file: BinaryIO, *, domain_filter: Collection[str] = ())
items = [InventoryItem.parse_sphinx(line.decode("utf8")) for line in lines]
if domain_filter:
items = [item for item in items if item.domain in domain_filter]
return cls(items)
return cls(sorted(items, key=lambda item: (item.domain, item.name)))

0 comments on commit 9371e9f

Please sign in to comment.