forked from shreyasmene06/pyvm-updater
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_requirements.py
More file actions
executable file
·193 lines (156 loc) · 6.04 KB
/
check_requirements.py
File metadata and controls
executable file
·193 lines (156 loc) · 6.04 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env python3
"""
Pre-installation checker for Python Version Manager
Verifies system requirements and dependencies before installation
"""
import platform
import subprocess
import sys
def check_python_version() -> bool:
"""Check if Python version meets minimum requirements"""
print("✓ Checking Python version...")
version = sys.version_info
if version.major >= 3 and version.minor >= 7:
print(f" ✓ Python {version.major}.{version.minor}.{version.micro} (minimum 3.7 required)")
return True
else:
print(f" ✗ Python {version.major}.{version.minor}.{version.micro} is too old!")
print(" Please upgrade to Python 3.7 or higher")
return False
def check_pip() -> bool:
"""Check if pip is installed"""
print("✓ Checking pip...")
try:
result = subprocess.run([sys.executable, "-m", "pip", "--version"], capture_output=True, text=True, check=True)
print(f" ✓ pip is installed: {result.stdout.strip()}")
return True
except subprocess.CalledProcessError:
print(" ✗ pip is not installed!")
print(" Install with: python -m ensurepip --upgrade")
return False
except Exception as e:
print(f" ✗ Error checking pip: {e}")
return False
def check_internet() -> bool:
"""Check basic internet connectivity"""
print("✓ Checking internet connectivity...")
try:
import socket
socket.create_connection(("www.python.org", 443), timeout=5)
print(" ✓ Internet connection OK")
return True
except OSError:
print(" ⚠ Cannot reach python.org")
print(" Internet connection may be required for updates")
return False
def check_existing_dependencies() -> dict[str, bool]:
"""Check if required packages are already installed"""
print("✓ Checking existing dependencies...")
packages: dict[str, bool] = {"requests": False, "beautifulsoup4": False, "packaging": False, "click": False}
for package in packages:
try:
__import__(package if package != "beautifulsoup4" else "bs4")
print(f" ✓ {package} already installed")
packages[package] = True
except ImportError:
print(f" ○ {package} will be installed")
packages[package] = False
return packages
def check_permissions() -> bool:
"""Check if user has permission to install packages"""
print("✓ Checking installation permissions...")
# Try to check site-packages location
try:
import site
site_packages = site.getsitepackages()
print(f" ○ Will install to: {site_packages[0] if site_packages else 'default location'}")
# On Unix systems, check if we need sudo
if platform.system().lower() in ["linux", "darwin"]:
import os
if not os.access(site_packages[0] if site_packages else "/usr/local", os.W_OK):
print(" ⚠ May require sudo for system-wide installation")
print(" Consider using: pip install --user")
return False
return True
except Exception as e:
print(f" ⚠ Could not check permissions: {e}")
return True
def check_os_support() -> bool:
"""Check if OS is supported"""
print("✓ Checking operating system...")
os_name = platform.system()
if os_name == "Windows":
print(f" ✓ Windows detected: {platform.release()}")
return True
elif os_name == "Linux":
print(f" ✓ Linux detected: {platform.release()}")
# Check for package managers
import shutil
if shutil.which("apt"):
print(" - apt package manager found")
elif shutil.which("dnf"):
print(" - dnf package manager found")
elif shutil.which("yum"):
print(" - yum package manager found")
else:
print(" ⚠ No supported package manager found")
return True
elif os_name == "Darwin":
print(f" ✓ macOS detected: {platform.mac_ver()[0]}")
import shutil
if shutil.which("brew"):
print(" - Homebrew found")
else:
print(" ⚠ Homebrew not found (recommended for easy updates)")
return True
else:
print(f" ⚠ Unsupported OS: {os_name}")
return False
def main() -> int:
"""Run all checks"""
print("=" * 60)
print(" Python Version Manager - Pre-Installation Check")
print("=" * 60)
print()
checks: dict[str, bool] = {
"Python version": check_python_version(),
"pip": check_pip(),
"Internet": check_internet(),
"OS support": check_os_support(),
"Permissions": check_permissions(),
}
# Check dependencies (informational only)
packages = check_existing_dependencies()
print()
print("=" * 60)
print(" Summary")
print("=" * 60)
critical_checks = ["Python version", "pip", "OS support"]
all_critical_passed = all(checks[check] for check in critical_checks if check in checks)
if all_critical_passed:
print("✓ All critical checks passed!")
print()
print("Ready to install. Run:")
print(" pip install -e .")
print()
print("Or for user-only installation:")
print(" pip install --user -e .")
print()
missing_packages = [pkg for pkg, installed in packages.items() if not installed]
if missing_packages:
print("The following packages will be installed automatically:")
for pkg in missing_packages:
print(f" - {pkg}")
return 0
else:
print("✗ Some critical checks failed!")
print()
print("Please fix the issues above before installing.")
failed = [check for check, passed in checks.items() if not passed and check in critical_checks]
if failed:
print("\nFailed checks:")
for check in failed:
print(f" - {check}")
return 1
if __name__ == "__main__":
sys.exit(main())