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

fix: manual nav reference for mkdocs; bumps version #335

Merged
merged 1 commit into from
Mar 19, 2024
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
18 changes: 18 additions & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,21 @@ copyright: Copyright © 2013 - 2024 Konsta Vesterinen

nav:
- Home: index.md
- API:
- references/between.md
- references/btc_address.md
- references/card.md
- references/country_code.md
- references/domain.md
- references/email.md
- references/hashes.md
- references/hostname.md
- references/i18n.md
- references/iban.md
- references/ip_address.md
- references/length.md
- references/mac_address.md
- references/slug.md
- references/url.md
- references/utils.md
- references/uuid.md
33 changes: 3 additions & 30 deletions package/export/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path
from shutil import copy, move, rmtree
from subprocess import Popen # nosec
from typing import Dict, List

__all__ = ("generate_documentation",)

Expand Down Expand Up @@ -38,39 +37,11 @@ def _parse_package(source: Path):
yield (namespace.module, namespace.names)


def _generate_reference(source: Path, destination: Path, ext: str):
"""Generate reference."""
nav_items: Dict[str, List[str]] = {"API": []}
# generate reference content
for module_name, aliases in _parse_package(source):
for alias in aliases:
_write_ref_content(destination / f"{module_name}.{ext}", module_name, alias.name)
if ext == "md":
nav_items["API"].append(f"references/{module_name}.md")
return nav_items


def _update_mkdocs_config(source: Path, destination: Path, nav_items: Dict[str, List[str]]):
"""Temporary update to mkdocs config."""
# external
from yaml import safe_dump, safe_load

copy(source, destination)
with open(source, "rt") as mkf:
mkdocs_conf = safe_load(mkf)
mkdocs_conf["nav"] += [nav_items]
with open(source, "wt") as mkf:
safe_dump(mkdocs_conf, mkf, sort_keys=False)


def _gen_md_docs(source: Path, refs_path: Path):
"""Generate Markdown docs."""
# remove existing markdown files
for md_files in (source / "docs/references").glob("*.md"):
md_files.unlink()
nav_items = _generate_reference(source / "src/validators/__init__.py", refs_path, "md")
# backup mkdocs config
_update_mkdocs_config(source / "mkdocs.yaml", source / "mkdocs.bak.yaml", nav_items)
# build mkdocs as subprocess
mkdocs_build = Popen(("mkdocs", "build")) # nosec
mkdocs_build.communicate()
Expand All @@ -97,7 +68,9 @@ def _gen_rst_docs(source: Path, refs_path: Path, only_web: bool = False, only_ma
+ "\n references/*\n"
)
# generate RST reference documentation
_generate_reference(source / "src/validators/__init__.py", refs_path, "rst")
for module_name, aliases in _parse_package(source / "src/validators/__init__.py"):
for alias in aliases:
_write_ref_content(refs_path / f"{module_name}.rst", module_name, alias.name)
exit_code = 0
if not only_man:
# build sphinx web pages as subprocess
Expand Down
2 changes: 1 addition & 1 deletion src/validators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@
"validator",
)

__version__ = "0.23.0"
__version__ = "0.23.1"
Loading