8000 Merge pull request #1263 from allthedata/master · python/mypy@5cd8319 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5cd8319

Browse files
committed
Merge pull request #1263 from allthedata/master
Fix for issue #1225
2 parents 75c1c42 + 679a72b commit 5cd8319

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

mypy/build.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,26 @@ def build(sources: List[BuildSource],
213213

214214

215215
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+
"""
217221
if not bin_dir:
218222
mypy_package = os.path.dirname(__file__)
219223
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)
223230
# 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')
227236
subdir = os.path.join(parent, 'lib', 'mypy')
228237
if os.path.isdir(subdir):
229238
# If installed via buildout, the __file__ is
@@ -240,7 +249,7 @@ def default_data_dir(bin_dir: str) -> str:
240249
return os.path.join(dir, 'Lib', 'mypy')
241250
elif base == 'scripts':
242251
# Assume that we have a repo check out or unpacked source tarball.
243-
return os.path.dirname(bin_dir)
252+
return dir
244253
elif base == 'bin':
245254
# Installed to somewhere (can be under /usr/local or anywhere).
246255
return os.path.join(dir, 'lib', 'mypy')

0 commit comments

Comments
 (0)
0