forked from Radio-Spectrum/SHARC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
78 lines (61 loc) · 2.44 KB
/
install.py
File metadata and controls
78 lines (61 loc) · 2.44 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
import os
import sys
import subprocess
from pathlib import Path
import platform
def run_command(command, shell=False):
"""Run a shell command.
Args:
command (list or str): The command to execute.
shell (bool): Whether to use the shell.
Raises:
SystemExit: If the command fails.
"""
try:
subprocess.check_call(command, shell=shell)
except subprocess.CalledProcessError as e:
print(f"Error: Command '{' '.join(command)}' failed with exit code {e.returncode}")
sys.exit(e.returncode)
def main():
"""Run the installer script main entry point."""
if int("".join(sys.version.split(" ")[0].split("."))) > 3120:
print("- Compatible Python version successfully recognized, starting installation process...")
start_install()
else:
print(f"- Error: Try updating Python to version 3.12 or above! \n - Current Python version: {sys.version}")
def start_install():
"""Start the SHARC installation process."""
print("- SHARC Installer Starting...")
# Set up path
project_root = Path(__file__).resolve().parent
venv_path = project_root / ".venv"
# Create venv
if not venv_path.exists():
print("- Creating virtual environment...")
run_command([sys.executable, "-m", "venv", str(venv_path)])
else:
print("- Virtual environment already exists.")
# Activate venv
if platform.system() == "Windows":
pip_executable = venv_path / "Scripts" / "pip.exe"
else:
pip_executable = venv_path / "bin" / "pip"
if not pip_executable.exists():
print("- Could not locate pip inside virtual environment.")
sys.exit(1)
requirements_file = project_root / "requirements.txt"
if not requirements_file.exists():
print("- requirements.txt not found.")
sys.exit(1)
print("- Installing dependencies from requirements.txt...")
run_command([str(pip_executable), "install", "-r", str(requirements_file)])
print("- Installing SHARC in editable mode...")
run_command([str(pip_executable), "install", "-e", str(project_root)])
print("\n- SHARC installation complete!")
print("- To activate your virtual environment, run:")
if platform.system() == "Windows":
print(r".venv\Scripts\activate")
else:
print("source .venv/bin/activate")
if __name__ == "__main__":
main()