Skip to content

Commit

Permalink
Merge pull request #335 from yozachar/workshop
Browse files Browse the repository at this point in the history
fix: manual nav reference for mkdocs; bumps version
  • Loading branch information
yozachar authored Mar 19, 2024
2 parents 2fb85bb + 285936c commit c2d3fb7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
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"

0 comments on commit c2d3fb7

Please sign in to comment.