PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
Functions | Variables
stamp_docs_revision Namespace Reference

Functions

str git_output (*str args)
 Return trimmed output from one Git command.
 
argparse.Namespace parse_args ()
 Parse generated-documentation stamping arguments.
 
int main ()
 Write revision metadata and load it on every generated HTML page.
 

Variables

 REPO_ROOT = Path(__file__).resolve().parents[2]
 

Detailed Description

Stamp generated Doxygen HTML with the Git revision it documents.

Function Documentation

◆ git_output()

str stamp_docs_revision.git_output ( *str  args)

Return trimmed output from one Git command.

Parameters
[in]argsArguments passed after git.
Returns
Decoded, trimmed Git stdout.

Definition at line 15 of file stamp_docs_revision.py.

15def git_output(*args: str) -> str:
16 """!
17 @brief Return trimmed output from one Git command.
18 @param[in] args Arguments passed after `git`.
19 @return Decoded, trimmed Git stdout.
20 """
21
22 return subprocess.check_output(["git", *args], cwd=REPO_ROOT, text=True).strip()
23
24
Here is the caller graph for this function:

◆ parse_args()

argparse.Namespace stamp_docs_revision.parse_args ( )

Parse generated-documentation stamping arguments.

Returns
Parsed command-line namespace.

Definition at line 25 of file stamp_docs_revision.py.

25def parse_args() -> argparse.Namespace:
26 """!
27 @brief Parse generated-documentation stamping arguments.
28 @return Parsed command-line namespace.
29 """
30
31 parser = argparse.ArgumentParser(description=__doc__)
32 parser.add_argument("--html-dir", type=Path, required=True, help="generated Doxygen HTML directory")
33 return parser.parse_args()
34
35
Here is the caller graph for this function:

◆ main()

int stamp_docs_revision.main ( )

Write revision metadata and load it on every generated HTML page.

Returns
Process status code.

Definition at line 36 of file stamp_docs_revision.py.

36def main() -> int:
37 """!
38 @brief Write revision metadata and load it on every generated HTML page.
39 @return Process status code.
40 """
41
42 args = parse_args()
43 html_dir = args.html_dir.resolve()
44 if not html_dir.is_dir():
45 raise SystemExit(f"HTML directory does not exist: {html_dir}")
46 sha = git_output("rev-parse", "HEAD")
47 remote = git_output("remote", "get-url", "origin")
48 if remote.startswith("git@github.com:"):
49 remote = "https://github.com/" + remote[len("git@github.com:"):]
50 if remote.endswith(".git"):
51 remote = remote[:-4]
52 revision = {
53 "sha": sha,
54 "short_sha": sha[:12],
55 "commit_url": f"{remote}/commit/{sha}",
56 "clean": not bool(git_output("status", "--porcelain")),
57 }
58 (html_dir / "picurv-docs-revision.js").write_text(
59 "window.PICURV_DOCS_REVISION = " + json.dumps(revision, sort_keys=True) + ";\n",
60 encoding="utf-8",
61 )
62 for page in html_dir.rglob("*.html"):
63 relative = page.relative_to(html_dir)
64 script_path = "../picurv-docs-revision.js" if relative.parts[0] == "search" else "picurv-docs-revision.js"
65 content = page.read_text(encoding="utf-8")
66 if "picurv-docs-revision.js" not in content:
67 content = content.replace("</head>", f'<script src="{script_path}"></script>\n</head>')
68 page.write_text(content, encoding="utf-8")
69 print(f"Stamped generated documentation through commit {sha}.")
70 return 0
71
72
int main(int argc, char **argv)
Entry point for the postprocessor executable.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ REPO_ROOT

stamp_docs_revision.REPO_ROOT = Path(__file__).resolve().parents[2]

Definition at line 12 of file stamp_docs_revision.py.