summaryrefslogtreecommitdiff
path: root/scripts/install_api.py
diff options
context:
space:
mode:
authordeadc0de6 <info@deadc0de.ch>2024-03-01 10:59:00 +0100
committerxusheng <xusheng@vector35.com>2024-05-24 14:50:55 +0800
commit5ec6a03709395cd0cfd5193ebc3ed4abbfc5f597 (patch)
treefd3193441614cbfd857fa6cae5f61cbbba08c5d9 /scripts/install_api.py
parent9f6774bc41896e48f55c48b32f8d67cd6dd0f8aa (diff)
ensures python site package dir exists
Diffstat (limited to 'scripts/install_api.py')
-rwxr-xr-xscripts/install_api.py34
1 files changed, 26 insertions, 8 deletions
diff --git a/scripts/install_api.py b/scripts/install_api.py
index 5e93064b..97584000 100755
--- a/scripts/install_api.py
+++ b/scripts/install_api.py
@@ -40,6 +40,21 @@ def check_virtual_environment() -> bool:
return False
+def getsitepackage() -> str:
+ """
+ gets the site package and creates it if needed
+ returns empty if fails
+ """
+ install_path = getsitepackages()[0]
+ if not os.path.exists(install_path):
+ try:
+ os.makedirs(install_path, exist_ok=True)
+ except OSError:
+ print_error(f"Root install specified but cannot create {install_path}")
+ return ''
+ return install_path
+
+
def binaryninja_installed() -> bool:
try:
binaryninja = importlib.util.find_spec("binaryninja")
@@ -121,20 +136,20 @@ def install(interactive=False, on_root=False, on_pyenv=False) -> bool:
api_path = new_path
if on_root:
- install_path = getsitepackages()[0]
- if not os.access(install_path, os.W_OK):
- print_error(f"Root install specified but cannot write to {install_path}")
+ install_path = getsitepackage()
+ if not install_path or not os.access(install_path, os.W_OK):
+ print_error(f"Root install specified but cannot write to \"{install_path}\"")
return False
else:
- print(f"Installing on root site: {install_path}")
+ print(f"Installing on root site: \"{install_path}\"")
elif on_pyenv:
- install_path = getsitepackages()[0]
- print(f"Installing on pyenv site: {install_path}")
+ install_path = getsitepackage()
+ print(f"Installing on pyenv site: \"{install_path}")
elif check_virtual_environment():
- install_path = getsitepackages()[0]
- print(f"Installing on virtual environment site: {install_path}")
+ install_path = getsitepackage()
+ print(f"Installing on virtual environment site: \"{install_path}\"")
else:
if not check_enableusersite():
@@ -146,6 +161,9 @@ def install(interactive=False, on_root=False, on_pyenv=False) -> bool:
os.makedirs(install_path)
print(f"Installing on user site: {install_path}")
+ if not install_path:
+ print_error("empty site packages path")
+ return False
binaryninja_pth_path = os.path.join(install_path, "binaryninja.pth")
with open(binaryninja_pth_path, 'wb') as pth_file:
pth_file.write((api_path + '\n').encode("charmap"))