Skip to content

Commit 8845c32

Browse files
authored
Merge pull request #7 from ihmeuw/chore/auto-update-project-from-template
[Actions] Auto-Update cookiecutter template
2 parents f7af88e + 3921f9b commit 8845c32

File tree

7 files changed

+117
-15
lines changed

7 files changed

+117
-15
lines changed

.cruft.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"template": "https://github.com/collijk/python-package-cookiecutter",
3-
"commit": "7e9285f84cc6b52165dbc97b9a0d4f059d0f6818",
3+
"commit": "8e2aaf58b416eecf27f0021e9ee770a34688fff9",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {
@@ -11,7 +11,8 @@
1111
"project_slug": "rra-tools",
1212
"package_name": "rra_tools",
1313
"project_short_description": "Common utilities for IHME Rapid Response team pipelines.",
14-
"_template": "https://github.com/collijk/python-package-cookiecutter"
14+
"_template": "https://github.com/collijk/python-package-cookiecutter",
15+
"_commit": "8e2aaf58b416eecf27f0021e9ee770a34688fff9"
1516
}
1617
},
1718
"directory": null
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build and Deploy Docs
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
types:
9+
- closed
10+
11+
jobs:
12+
build-and-deploy-docs:
13+
if: ${{ github.event.pull_request.merged }} or ${{ github.event_name == 'workflow_dispatch' }}
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.GH_TOKEN }}
19+
- uses: ./.github/actions/python-poetry-env
20+
- name: Deploy docs
21+
run: poetry run mkdocs gh-deploy --force

docs/api_docs.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

mkdocs.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ theme:
1414
name: Switch to light mode
1515

1616
nav:
17-
- Introduction: 'index.md'
18-
- api_docs.md
19-
- changelog.md
17+
- Home: 'index.md'
18+
- Code Reference: reference/
19+
- Changelog: changelog.md
2020

2121
watch:
2222
- src/rra_tools
@@ -61,6 +61,12 @@ markdown_extensions:
6161
plugins:
6262
- table-reader
6363
- search
64+
- gen-files:
65+
scripts:
66+
- scripts/gen_ref_pages.py
67+
- literate-nav:
68+
nav_vile: SUMMARY.md
69+
- section-index
6470
- mkdocstrings:
6571
default_handler: python
6672
handlers:

poetry.lock

Lines changed: 43 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ requests = "^2.32.2"
4343
mkdocstrings = {version = ">=0.23", extras = ["python"]}
4444
mkdocs-material = "*"
4545
mkdocs-table-reader-plugin = "*"
46+
mkdocs-gen-files = "^0.5.0"
47+
mkdocs-literate-nav = "^0.6.1"
48+
mkdocs-section-index = "^0.3.9"
4649
mypy = "*"
4750
pre-commit = "*"
4851
pymdown-extensions = "*"
@@ -90,6 +93,9 @@ ignore-init-module-imports = true
9093
"ARG", # "Unused function argument". Fixtures are often unused.
9194
"S105", # "Possible hardcoded password".
9295
]
96+
"scripts/**" = [
97+
"INP001", # "Scripts are not part of a package."
98+
]
9399

94100
[tool.ruff.lint.mccabe]
95101
max-complexity = 10
@@ -134,9 +140,3 @@ module = [
134140
"pathos.*",
135141
]
136142
ignore_missing_imports = true
137-
138-
# [[tool.mypy.overrides]]
139-
# module = [
140-
# "tests/my_thing/test_my_thing",
141-
# ]
142-
# disallow_untyped_defs = false

scripts/gen_ref_pages.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Generate the code reference pages and navigation."""
2+
3+
from pathlib import Path
4+
5+
import mkdocs_gen_files
6+
7+
nav = mkdocs_gen_files.Nav() # type: ignore[attr-defined, no-untyped-call]
8+
9+
root = Path(__file__).parent.parent
10+
src = root / "src"
11+
12+
for path in sorted(src.rglob("*.py")):
13+
module_path = path.relative_to(src).with_suffix("")
14+
doc_path = path.relative_to(src).with_suffix(".md")
15+
full_doc_path = Path("reference", doc_path)
16+
17+
parts = tuple(module_path.parts)
18+
19+
if parts[-1] == "__init__":
20+
parts = parts[:-1]
21+
doc_path = doc_path.with_name("index.md")
22+
full_doc_path = full_doc_path.with_name("index.md")
23+
elif parts[-1] == "__main__":
24+
continue
25+
26+
nav[parts] = doc_path.as_posix()
27+
28+
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
29+
ident = ".".join(parts)
30+
fd.write(f"::: {ident}")
31+
32+
mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(root))
33+
34+
with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:
35+
nav_file.writelines(nav.build_literate_nav())

0 commit comments

Comments
 (0)