-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
51 lines (40 loc) · 1.65 KB
/
setup.py
File metadata and controls
51 lines (40 loc) · 1.65 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
import sys
import subprocess
import pkg_resources
def check_requirements():
"""Check if all requirements from requirements.txt are installed."""
with open("requirements.txt") as f:
required_packages = f.read().splitlines()
installed_packages = {pkg.key for pkg in pkg_resources.working_set}
for package in required_packages:
package_name = package.split("==")[0] if "==" in package else package
if package_name not in installed_packages:
print(f"{package_name} not installed. Attempting to install...")
subprocess.call(f"pip install {package}", shell=True)
def check_install_command(command, install_command):
"""Check if a command is available, and if not, attempt to install it."""
if subprocess.call(
["which", command], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
):
print(f"{command} not found. Attempting to install...")
subprocess.call(install_command, shell=True)
def main():
try:
# Check for all requirements
check_requirements()
except Exception as e:
print(f"Error while checking requirements: {e}")
return
try:
# Check for Graphviz
if sys.platform.startswith("linux"):
check_install_command("dot", "sudo apt-get install graphviz")
elif sys.platform == "darwin":
check_install_command("dot", "brew install graphviz")
elif sys.platform == "win32":
print("Please install Graphviz from https://graphviz.org/download/")
except Exception as e:
print(f"Error while checking Graphviz: {e}")
return
if __name__ == "__main__":
main()