-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_and_run.py
More file actions
63 lines (55 loc) · 2.18 KB
/
Copy pathsetup_and_run.py
File metadata and controls
63 lines (55 loc) · 2.18 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
import os
import subprocess
import sys
from sysconfig import get_path
def create_virtualenv():
"""Create a virtual environment if it doesn't exist."""
try:
if not os.path.exists(".venv"):
print("Creating virtual environment...")
subprocess.check_call([sys.executable, "-m", "venv", ".venv"])
else:
print("Virtual environment already exists.")
except subprocess.CalledProcessError as e:
print(f"Error creating virtual environment: {e}")
sys.exit(1)
def install_requirements():
"""Install required packages from requirements.txt."""
try:
requirements_path = "requirements.txt"
if not os.path.exists(requirements_path):
print(f"Error: {requirements_path} not found.")
sys.exit(1)
print("Installing requirements...")
pip_path = os.path.join(".venv", get_path("scripts"), "pip")
subprocess.check_call([pip_path, "install", "-r", requirements_path])
except subprocess.CalledProcessError as e:
print(f"Error installing requirements: {e}")
sys.exit(1)
def run_script():
"""Run the main Python script."""
try:
print("Running the main script...")
script_path = os.path.join(os.path.dirname(__file__), "codebase_analysis.py")
if not os.path.exists(script_path):
print(f"Error: {script_path} not found.")
sys.exit(1)
python_path = os.path.join(".venv", get_path("scripts"), "python")
subprocess.check_call([python_path, script_path])
except subprocess.CalledProcessError as e:
print(f"Error running the main script: {e}")
sys.exit(1)
def check_python_version():
"""Ensure the script is run with a compatible Python version."""
if sys.version_info < (3, 6):
print("Error: Python 3.6 or higher is required.")
sys.exit(1)
def main():
print("Setup and Run Script Started...")
check_python_version()
create_virtualenv()
install_requirements()
run_script()
print("Setup and Run Script Completed Successfully!")
if __name__ == "__main__":
main()