-
Notifications
You must be signed in to change notification settings - Fork 87
/
init_repo.py
57 lines (40 loc) · 1.52 KB
/
init_repo.py
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
import os
import subprocess # nosec
import sys
def log(message: str) -> None:
print(f"[init_repo] {message}")
def check_python_version() -> bool:
"""
Check if the current Python version is between 3.6 and 3.8 inclusive.
"""
version_info = sys.version_info
if version_info.major != 3:
return False
if version_info.minor < 6 or version_info.minor > 8:
return False
return True
def find_python() -> str:
"""
Get the path of the currently running Python executable.
"""
return sys.executable
def main() -> None:
if not check_python_version():
log("Error: Supported Python versions are between 3.6 and 3.8.")
log(f"Detected Python version: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
sys.exit(1)
python_executable = find_python()
log(f"Using Python executable: {python_executable}")
log("Creating virtual environment")
subprocess.run(f"{python_executable} -m venv .venv", shell=True) # nosec
log("Installing Python packages")
py_path = os.path.join(".venv", "bin", "python")
if sys.platform.startswith("win"):
py_path = os.path.join(".venv", "Scripts", "python")
subprocess.run(f"{py_path} -m pip install --upgrade pip", shell=True) # nosec
# Install packages from requirements.txt
subprocess.run(f"{py_path} -m pip install -r requirements.txt", shell=True) # nosec
log("Python packages installed successfully")
log("DONE!")
if __name__ == "__main__":
main()