Skip to content

Commit

Permalink
fix: fix sorting of modules (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 authored Feb 7, 2025
1 parent c8d9691 commit f6a2514
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/mkdocs_api_autonav/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _iter_modules(
path where the corresponding documentation file should be written.
"""
root_module = Path(root_module)
for abs_path in _iter_py_files(root_module, on_implicit_namespace_packge):
for abs_path in sorted(_iter_py_files(root_module, on_implicit_namespace_packge)):
rel_path = abs_path.relative_to(root_module.parent)
doc_path = rel_path.with_suffix(".md")
full_doc_path = Path(docs_root, doc_path)
Expand Down
20 changes: 19 additions & 1 deletion tests/test_mkdocs_api_autonav.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from mkdocs.exceptions import Abort
from pytest import MonkeyPatch

from mkdocs_api_autonav.plugin import PluginConfig
from mkdocs_api_autonav.plugin import PluginConfig, _iter_modules

if TYPE_CHECKING:
from _pytest.logging import LogCaptureFixture
Expand Down Expand Up @@ -67,6 +67,24 @@ def test_build(repo1: Path) -> None:
assert (sub_sub / "index.html").is_file()


def test_sorting(repo1: Path) -> None:
package = repo1 / "src" / "my_library"
(package / "z_submod.py").touch()
(package / "a_submod.py").touch()
modules = [
x
for x, *_ in _iter_modules(repo1 / "src" / "my_library", str(repo1), "skip")
if not any(part.startswith("_") for part in x)
]
assert modules == [
("my_library",),
("my_library", "a_submod"),
("my_library", "submod"),
("my_library", "submod", "sub_submod"),
("my_library", "z_submod"),
]


def test_build_without_mkdocstrings(repo1: Path, caplog: LogCaptureFixture) -> None:
cfg = cfg_dict()
cfg["plugins"].remove({"mkdocstrings": {}})
Expand Down

0 comments on commit f6a2514

Please sign in to comment.