Repository navigation
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·116 lines (93 loc) · 3.51 KB
/
Copy pathbuild.py
File metadata and controls
executable file
·116 lines (93 loc) · 3.51 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
"""
Build script for PlanExe documentation.
This script builds the docs from the PlanExe2 repo (docs/website/) and outputs to this repo.
"""
import os
import sys
import shutil
import subprocess
import tempfile
from pathlib import Path
# ANSI color codes
GREEN = '\033[0;32m'
YELLOW = '\033[1;33m'
RED = '\033[0;31m'
NC = '\033[0m' # No Color
def print_colored(message: str, color: str = NC):
"""Print a colored message."""
print(f"{color}{message}{NC}")
def main():
"""Main build function."""
# Configuration
planexe_repo = Path(os.environ.get("PLANEXE_REPO", "../PlanExe2"))
docs_source_dir = os.environ.get("DOCS_SOURCE_DIR", "docs/website")
output_dir = "site"
print_colored("Building PlanExe documentation...", GREEN)
# Check if PlanExe repo exists
if not planexe_repo.exists() or not planexe_repo.is_dir():
print_colored(
f"Error: PlanExe2 repo not found at {planexe_repo}",
RED
)
print("Set PLANEXE_REPO environment variable to point to the PlanExe2 repository")
sys.exit(1)
# Check if docs source directory exists
docs_source_path = planexe_repo / docs_source_dir
if not docs_source_path.exists() or not docs_source_path.is_dir():
print_colored(
f"Error: Documentation source directory not found at {docs_source_path}",
RED
)
print("Set DOCS_SOURCE_DIR environment variable if your docs are in a different directory")
sys.exit(1)
# Get the original directory
original_dir = Path.cwd()
mkdocs_yml = original_dir / "mkdocs.yml"
if not mkdocs_yml.exists():
print_colored(
f"Error: mkdocs.yml not found in {original_dir}",
RED
)
sys.exit(1)
# Create temporary directory for docs
with tempfile.TemporaryDirectory() as temp_docs:
temp_docs_path = Path(temp_docs)
# Create docs subdirectory (mkdocs expects docs_dir by default)
docs_dir = temp_docs_path / "docs"
docs_dir.mkdir()
# Copy docs from PlanExe repo into the docs subdirectory
print_colored(
f"Copying documentation from {docs_source_path}...",
YELLOW
)
shutil.copytree(docs_source_path, docs_dir, dirs_exist_ok=True)
# Copy mkdocs.yml to temp directory
shutil.copy2(mkdocs_yml, temp_docs_path / "mkdocs.yml")
# Build the documentation
print_colored("Building with mkdocs...", YELLOW)
try:
subprocess.run(
["mkdocs", "build", "--site-dir", output_dir],
cwd=temp_docs_path,
check=True
)
except subprocess.CalledProcessError as e:
print_colored(f"Error: mkdocs build failed: {e}", RED)
sys.exit(1)
except FileNotFoundError:
print_colored(
"Error: mkdocs command not found. Please install mkdocs-material.",
RED
)
sys.exit(1)
# Move output to current directory
built_site = temp_docs_path / output_dir
output_path = original_dir / output_dir
if output_path.exists():
shutil.rmtree(output_path)
shutil.move(str(built_site), str(output_path))
print_colored("✓ Documentation built successfully!", GREEN)
print_colored(f"Output is in the '{output_dir}' directory", GREEN)
if __name__ == "__main__":
main()