-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_pth.py
More file actions
42 lines (35 loc) · 1.27 KB
/
install_pth.py
File metadata and controls
42 lines (35 loc) · 1.27 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
#!/usr/bin/env python3
"""Install the superclient-init.pth file to enable automatic loading"""
import os
import sys
import shutil
import site
def install_pth():
"""Install the .pth file to the appropriate site-packages directory"""
# Get the path to the .pth file from package resources
import superclient
package_dir = os.path.dirname(superclient.__file__)
source = os.path.join(package_dir, "superclient-init.pth")
if not os.path.exists(source):
print(f"Error: {source} not found")
return False
# Find site-packages directory
site_packages = None
for path in sys.path:
if path.endswith('site-packages') and os.path.isdir(path):
site_packages = path
break
if not site_packages:
site_packages = site.getsitepackages()[0]
dest = os.path.join(site_packages, "superclient-init.pth")
try:
shutil.copy2(source, dest)
print(f"Successfully installed {dest}")
print("Superclient will now load automatically!")
return True
except Exception as e:
print(f"Error installing .pth file: {e}")
print(f"You may need to run this script with sudo or as administrator")
return False
if __name__ == "__main__":
install_pth()