@@ -213,17 +213,26 @@ def build(sources: List[BuildSource],
213
213
214
214
215
215
def default_data_dir (bin_dir : str ) -> str :
216
- # TODO fix this logic
216
+ """Returns directory containing typeshed directory
217
+
218
+ Args:
219
+ bin_dir: directory containing the mypy script
220
+ """
217
221
if not bin_dir :
218
222
mypy_package = os .path .dirname (__file__ )
219
223
parent = os .path .dirname (mypy_package )
220
- if os .path .basename (parent ) == 'site-packages' :
221
- # Installed in site-packages, but invoked with python3 -m mypy;
222
- # __file__ is .../blah/lib/python3.N/site-packages/mypy/__init__.py;
224
+ if (os .path .basename (parent ) == 'site-packages' or
225
+ os .path .basename (parent ) == 'dist-packages' ):
226
+ # Installed in site-packages or dist-packages, but invoked with python3 -m mypy;
227
+ # __file__ is .../blah/lib/python3.N/site-packages/mypy/build.py
228
+ # or .../blah/lib/python3.N/dist-packages/mypy/build.py (Debian)
229
+ # or .../blah/lib/site-packages/mypy/build.py (Windows)
223
230
# blah may be a virtualenv or /usr/local. We want .../blah/lib/mypy.
224
- lib = os .path .dirname (os .path .dirname (parent ))
225
- if os .path .basename (lib ) == 'lib' :
226
- return os .path .join (lib , 'mypy' )
231
+ lib = parent
232
+ for i in range (2 ):
233
+ lib = os .path .dirname (lib )
234
+ if os .path .basename (lib ) == 'lib' :
235
+ return os .path .join (lib , 'mypy' )
227
236
subdir = os .path .join (parent , 'lib' , 'mypy' )
228
237
if os .path .isdir (subdir ):
229
238
# If installed via buildout, the __file__ is
@@ -240,7 +249,7 @@ def default_data_dir(bin_dir: str) -> str:
240
249
return os .path .join (dir , 'Lib' , 'mypy' )
241
250
elif base == 'scripts' :
242
251
# Assume that we have a repo check out or unpacked source tarball.
243
- return os . path . dirname ( bin_dir )
252
+ return dir
244
253
elif base == 'bin' :
245
254
# Installed to somewhere (can be under /usr/local or anywhere).
246
255
return os .path .join (dir , 'lib' , 'mypy' )
0 commit comments