This repository was archived by the owner on Apr 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv_setup.py
More file actions
57 lines (44 loc) · 1.83 KB
/
Copy pathenv_setup.py
File metadata and controls
57 lines (44 loc) · 1.83 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
#!/usr/bin/env python3
"""Environment setup helper (cross-platform).
This script creates/uses a project-local .venv and installs requirements from
requirements.txt if present. It intentionally does NOT run the application.
Usage:
python env_setup.py # create/use .venv and install deps
"""
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
VENV = ROOT / ".venv"
def ensure_venv(venv_path: Path) -> Path:
if not venv_path.exists():
print(f"Creating virtualenv at {venv_path}")
subprocess.check_call([sys.executable, "-m", "venv", str(venv_path)])
if os.name == "nt":
return venv_path / "Scripts" / "python.exe"
return venv_path / "bin" / "python"
def install_requirements(python: Path) -> None:
req = ROOT / "requirements.txt"
if req.exists():
print("Installing requirements from requirements.txt (if needed)...")
subprocess.check_call([str(python), "-m", "pip", "install", "--upgrade", "pip", "setuptools", "wheel"])
subprocess.check_call([str(python), "-m", "pip", "install", "-r", str(req)])
else:
print("No requirements.txt found — nothing to install.")
def main() -> int:
python_in_venv = ensure_venv(VENV)
install_requirements(python_in_venv)
print("")
print("Environment ready.")
print("To run the application, activate the venv and run your command, e.g:")
if os.name == "nt":
print(r" .\.venv\Scripts\activate.bat")
print(r" python src\xy_runner\xy_runner.py --config examples\example_xy\SIM_sample_SVG.yaml")
else:
print(" source .venv/bin/activate")
print(" python src/xy_runner/xy_runner.py --config examples/example_xy/SIM_sample_SVG.yaml")
return 0
if __name__ == "__main__":
raise SystemExit(main())