11#!/usr/bin/env python3
22"""
3- Wrapper script that calls the main start_docs.py in the Reloaded directory with parameters .
3+ Script to set up virtual environment and start MkDocs live server for documentation .
44"""
55
66import subprocess
77import sys
8+ import os
89from pathlib import Path
910
11+ def run_command (cmd , cwd = None ):
12+ """Run a command and handle errors."""
13+ print (f"Running: { ' ' .join (cmd )} " )
14+ try :
15+ result = subprocess .run (cmd , cwd = cwd , check = True , capture_output = False )
16+ return result
17+ except subprocess .CalledProcessError as e :
18+ print (f"Error running command: { e } " )
19+ sys .exit (1 )
20+
1021def main ():
11- """Call the main start_docs.py script with prs-rs specific parameters."""
12- # Get the directory where this script is located
13- script_dir = Path (__file__ ).parent
14- reloaded_script = script_dir / "docs" / "Reloaded" / "start_docs.py"
22+ """Main function to set up docs environment."""
23+ import argparse
1524
16- if not reloaded_script .exists ():
17- print (f"Error: Could not find { reloaded_script } " )
18- sys .exit (1 )
25+ parser = argparse .ArgumentParser (description = 'Set up documentation environment' )
26+ parser .add_argument ('--docs-dir' , type = str , help = 'Documentation directory containing mkdocs.yml and docs/ subfolder (default: script directory)' )
27+ parser .add_argument ('--project-name' , type = str , default = 'documentation' , help = 'Project name for messages' )
28+ args = parser .parse_args ()
29+
30+ # Use docs directory if provided, otherwise use script directory
31+ if args .docs_dir :
32+ script_dir = Path (args .docs_dir )
33+ else :
34+ script_dir = Path (__file__ ).parent
35+
36+ venv_dir = script_dir / "venv"
37+
38+ print (f"Setting up { args .project_name } environment..." )
39+
40+ # Create virtual environment if it doesn't exist
41+ if not venv_dir .exists ():
42+ print ("Creating virtual environment..." )
43+ run_command ([sys .executable , "-m" , "venv" , "venv" ], cwd = script_dir )
44+ else :
45+ print ("Virtual environment already exists." )
46+
47+ # Determine the python executable in the venv
48+ if os .name == 'nt' : # Windows
49+ python_exe = venv_dir / "Scripts" / "python.exe"
50+ pip_exe = venv_dir / "Scripts" / "pip.exe"
51+ else : # Unix-like
52+ python_exe = venv_dir / "bin" / "python"
53+ pip_exe = venv_dir / "bin" / "pip"
54+
55+ # Install required packages
56+ print ("Installing required packages..." )
57+
58+ # Install from requirements.txt relative to this script if it exists
59+ script_requirements_file = Path (__file__ ).parent / "docs" / "requirements.txt"
60+ if script_requirements_file .exists ():
61+ print (f"Installing from { script_requirements_file } ..." )
62+ run_command ([str (pip_exe ), "install" , "-r" , str (script_requirements_file )], cwd = script_dir )
63+
64+ # Install from requirements.txt in docs directory if it exists
65+ requirements_file = script_dir / "docs" / "requirements.txt"
66+ if requirements_file .exists ():
67+ print (f"Installing from { requirements_file } ..." )
68+ run_command ([str (pip_exe ), "install" , "-r" , str (requirements_file )], cwd = script_dir )
1969
20- # Run the main script with parameters for prs-rs
21- print (f"Running prs-rs documentation setup from: { reloaded_script } " )
22- subprocess .run ([
23- sys .executable ,
24- str (reloaded_script ),
25- "--docs-dir" , str (script_dir ),
26- "--project-name" , "prs-rs documentation"
27- ], cwd = script_dir )
70+ # Start MkDocs live server
71+ print ("Starting MkDocs live server..." )
72+ print ("Documentation will be available at http://127.0.0.1:8000 (paste into browser address bar)" )
73+ print ("Press Ctrl+C to stop the server" )
74+ run_command ([str (python_exe ), "-m" , "mkdocs" , "serve" , "--livereload" ], cwd = script_dir )
2875
2976if __name__ == "__main__" :
3077 main ()
0 commit comments