@@ -40,6 +40,21 @@ def check_virtual_environment() -> bool:
40
40
return False
41
41
42
42
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
+
43
58
def binaryninja_installed () -> bool :
44
59
try :
45
60
binaryninja = importlib .util .find_spec ("binaryninja" )
@@ -121,20 +136,20 @@ def install(interactive=False, on_root=False, on_pyenv=False) -> bool:
121
136
api_path = new_path
122
137
123
138
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 } \" " )
127
142
return False
128
143
else :
129
- print (f"Installing on root site: { install_path } " )
144
+ print (f"Installing on root site: \" { install_path } \" " )
130
145
131
146
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 } " )
134
149
135
150
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 } \" " )
138
153
139
154
else :
140
155
if not check_enableusersite ():
@@ -146,6 +161,9 @@ def install(interactive=False, on_root=False, on_pyenv=False) -> bool:
146
161
os .makedirs (install_path )
147
162
print (f"Installing on user site: { install_path } " )
148
163
164
+ if not install_path :
165
+ print_error ("empty site packages path" )
166
+ return False
149
167
binaryninja_pth_path = os .path .join (install_path , "binaryninja.pth" )
150
168
with open (binaryninja_pth_path , 'wb' ) as pth_file :
151
169
pth_file .write ((api_path + '\n ' ).encode ("charmap" ))
0 commit comments