Skip to content

Commit 5ec6a03

Browse files
deadc0de6xusheng6
authored andcommitted
ensures python site package dir exists
1 parent 9f6774b commit 5ec6a03

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

scripts/install_api.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ def check_virtual_environment() -> bool:
4040
return False
4141

4242

43+
def getsitepackage() -> str:
44+
"""
45+
gets the site package and creates it if needed
46+
returns empty if fails
47+
"""
48+
install_path = getsitepackages()[0]
49+
if not os.path.exists(install_path):
50+
try:
51+
os.makedirs(install_path, exist_ok=True)
52+
except OSError:
53+
print_error(f"Root install specified but cannot create {install_path}")
54+
return ''
55+
return install_path
56+
57+
4358
def binaryninja_installed() -> bool:
4459
try:
4560
binaryninja = importlib.util.find_spec("binaryninja")
@@ -121,20 +136,20 @@ def install(interactive=False, on_root=False, on_pyenv=False) -> bool:
121136
api_path = new_path
122137

123138
if on_root:
124-
install_path = getsitepackages()[0]
125-
if not os.access(install_path, os.W_OK):
126-
print_error(f"Root install specified but cannot write to {install_path}")
139+
install_path = getsitepackage()
140+
if not install_path or not os.access(install_path, os.W_OK):
141+
print_error(f"Root install specified but cannot write to \"{install_path}\"")
127142
return False
128143
else:
129-
print(f"Installing on root site: {install_path}")
144+
print(f"Installing on root site: \"{install_path}\"")
130145

131146
elif on_pyenv:
132-
install_path = getsitepackages()[0]
133-
print(f"Installing on pyenv site: {install_path}")
147+
install_path = getsitepackage()
148+
print(f"Installing on pyenv site: \"{install_path}")
134149

135150
elif check_virtual_environment():
136-
install_path = getsitepackages()[0]
137-
print(f"Installing on virtual environment site: {install_path}")
151+
install_path = getsitepackage()
152+
print(f"Installing on virtual environment site: \"{install_path}\"")
138153

139154
else:
140155
if not check_enableusersite():
@@ -146,6 +161,9 @@ def install(interactive=False, on_root=False, on_pyenv=False) -> bool:
146161
os.makedirs(install_path)
147162
print(f"Installing on user site: {install_path}")
148163

164+
if not install_path:
165+
print_error("empty site packages path")
166+
return False
149167
binaryninja_pth_path = os.path.join(install_path, "binaryninja.pth")
150168
with open(binaryninja_pth_path, 'wb') as pth_file:
151169
pth_file.write((api_path + '\n').encode("charmap"))

0 commit comments

Comments
 (0)