-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
55 lines (47 loc) · 1.84 KB
/
setup.py
File metadata and controls
55 lines (47 loc) · 1.84 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
import os
import subprocess
import sys
from pathlib import Path
def create_virtualenv():
try:
print("Creating virtual environment...")
subprocess.run([sys.executable, "-m", "venv", "env"], check=True)
print("Virtual environment created successfully.")
except subprocess.CalledProcessError as e:
print(f"Error creating virtual environment: {e}")
sys.exit(1)
def install_requirements():
try:
print("Installing requirements...")
pip_path = os.path.join("env", "Scripts", "pip") if os.name == "nt" else os.path.join("env", "bin", "pip")
requirements_file = Path("requirements.txt")
if not requirements_file.exists():
print("Error: requirements.txt not found!")
sys.exit(1)
subprocess.run([pip_path, "install", "-r", str(requirements_file)], check=True)
print("Requirements installed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error installing requirements: {e}")
sys.exit(1)
def run_main():
try:
python_path = os.path.join("env", "Scripts", "python") if os.name == "nt" else os.path.join("env", "bin", "python")
main_file = Path("main.py")
if not main_file.exists():
print("Error: main.py not found!")
sys.exit(1)
subprocess.run([python_path, str(main_file)], check=True)
except subprocess.CalledProcessError as e:
print(f"Error running main.py: {e}")
sys.exit(1)
if __name__ == "__main__":
try:
if not os.path.exists("env"):
create_virtualenv()
install_requirements()
else:
print("Virtual environment already exists.")
run_main()
except KeyboardInterrupt:
print("\nSetup interrupted by user.")
sys.exit(1)