-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathmkdocs-build.py
More file actions
45 lines (36 loc) · 1.26 KB
/
Copy pathmkdocs-build.py
File metadata and controls
45 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import shutil
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
SOURCE_DIR = ROOT / "site_src"
SOURCE_FILES = (
"README.md",
"contributing.md",
"code-of-conduct.md",
)
CLEAN_AFTER_BUILD = True
def main() -> int:
if SOURCE_DIR.exists():
shutil.rmtree(SOURCE_DIR)
SOURCE_DIR.mkdir(parents=True, exist_ok=True)
for file_name in SOURCE_FILES:
source_path = ROOT / file_name
if not source_path.is_file():
print(f"Missing source file: {source_path}", file=sys.stderr)
exit(1)
shutil.copy2(source_path, SOURCE_DIR / file_name)
try:
subprocess.run(["mkdocs", "build"], cwd=ROOT, check=True)
except subprocess.CalledProcessError as exc:
print(f"mkdocs build failed with exit code {exc.returncode}", file=sys.stderr)
print(f"Temporary docs folder kept at: {SOURCE_DIR}", file=sys.stderr)
exit(exc.returncode)
if CLEAN_AFTER_BUILD:
shutil.rmtree(SOURCE_DIR)
print("mkdocs build completed successfully. Removed temporary docs folder.")
else:
print(f"mkdocs build completed successfully. Temporary docs folder kept at: {SOURCE_DIR}")
if __name__ == "__main__":
main()