-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgithub-actions-init.py
More file actions
101 lines (77 loc) · 2.43 KB
/
Copy pathgithub-actions-init.py
File metadata and controls
101 lines (77 loc) · 2.43 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import os
import platform
import shutil
import stat
import subprocess
import sys
from typing import List
def run_command(command: List[str]):
try:
return subprocess.run(
command,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
).stdout.strip()
except subprocess.CalledProcessError:
return None
def is_git_repo_and_on_branch(branch_name: str = "python"):
return (
run_command(["git", "rev-parse", "--is-inside-work-tree"])
and run_command(["git", "branch", "--show-current"]) == branch_name
)
def check_package(package_name: str):
try:
__import__(package_name)
return True
except ImportError:
return False
def delete_path(path: str):
if not os.path.exists(path):
print(f"Path '{path}' does not exist.")
return
try:
if os.path.isdir(path):
shutil.rmtree(path, ignore_errors=True)
else:
os.remove(path)
print(f"'{path}' deleted successfully.")
except OSError as e:
print(f"Error deleting '{path}': {e}")
def ensure_directories(directories: List[str]):
base_dir = os.path.dirname(os.path.abspath(__file__))
for d in directories:
full_path = os.path.join(base_dir, d)
os.makedirs(full_path, exist_ok=True)
os.chmod(full_path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
def run_pip_install(*requirements_files: str):
for req in requirements_files:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", req])
# ---- Packages ----
packages = ["pycountry", "django", "requests", "pytz", "timezonefinder"]
if platform.system() == "Windows" and is_git_repo_and_on_branch():
packages += ["PySide6", "wmi", "qtawesome", "nuitka"]
missing_packages = [pkg for pkg in packages if not check_package(pkg)]
if missing_packages:
print(f"Missing packages: {', '.join(missing_packages)}")
subprocess.check_call([sys.executable, "requirements_install.py", "--generate"])
run_pip_install(
"requirements.txt",
"requirements-base.txt",
"requirements-minimal.txt",
)
else:
print("All required packages are installed.")
# ---- Directories ----
dirs = [
".cache",
"config",
"assets/proxies",
"assets/chrome-profiles",
"assets/chrome",
"tmp/cookies",
"tmp/data",
"dist",
]
ensure_directories(dirs)