|
20 | 20 | import hashlib |
21 | 21 | import json |
22 | 22 | import os.path |
| 23 | +import pathlib |
23 | 24 | import re |
24 | 25 | import site |
25 | 26 | import stat |
@@ -326,7 +327,7 @@ def _build(sources: List[BuildSource], |
326 | 327 | # This seems the most reasonable place to tune garbage collection. |
327 | 328 | gc.set_threshold(50000) |
328 | 329 |
|
329 | | - data_dir = default_data_dir(bin_dir) |
| 330 | + data_dir = default_data_dir() |
330 | 331 | fscache = fscache or FileSystemCache() |
331 | 332 |
|
332 | 333 | search_paths = compute_search_paths(sources, options, data_dir, fscache, alt_lib_path) |
@@ -365,68 +366,9 @@ def _build(sources: List[BuildSource], |
365 | 366 | reports.finish() |
366 | 367 |
|
367 | 368 |
|
368 | | -def default_data_dir(bin_dir: Optional[str]) -> str: |
369 | | - """Returns directory containing typeshed directory |
370 | | -
|
371 | | - Args: |
372 | | - bin_dir: directory containing the mypy script |
373 | | - """ |
374 | | - if not bin_dir: |
375 | | - if os.name == 'nt': |
376 | | - prefixes = [os.path.join(sys.prefix, 'Lib')] |
377 | | - try: |
378 | | - prefixes.append(os.path.join(site.getuserbase(), 'lib')) |
379 | | - except AttributeError: |
380 | | - # getuserbase in not available in virtualenvs |
381 | | - prefixes.append(os.path.join(get_python_lib(), 'lib')) |
382 | | - for parent in prefixes: |
383 | | - data_dir = os.path.join(parent, 'mypy') |
384 | | - if os.path.exists(data_dir): |
385 | | - return data_dir |
386 | | - mypy_package = os.path.dirname(__file__) |
387 | | - parent = os.path.dirname(mypy_package) |
388 | | - if (os.path.basename(parent) == 'site-packages' or |
389 | | - os.path.basename(parent) == 'dist-packages'): |
390 | | - # Installed in site-packages or dist-packages, but invoked with python3 -m mypy; |
391 | | - # __file__ is .../blah/lib/python3.N/site-packages/mypy/build.py |
392 | | - # or .../blah/lib/python3.N/dist-packages/mypy/build.py (Debian) |
393 | | - # or .../blah/lib64/python3.N/dist-packages/mypy/build.py (Gentoo) |
394 | | - # or .../blah/lib/site-packages/mypy/build.py (Windows) |
395 | | - # blah may be a virtualenv or /usr/local. We want .../blah/lib/mypy. |
396 | | - lib = parent |
397 | | - for i in range(2): |
398 | | - lib = os.path.dirname(lib) |
399 | | - if os.path.basename(lib) in ('lib', 'lib32', 'lib64'): |
400 | | - return os.path.join(os.path.dirname(lib), 'lib/mypy') |
401 | | - subdir = os.path.join(parent, 'lib', 'mypy') |
402 | | - if os.path.isdir(subdir): |
403 | | - # If installed via buildout, the __file__ is |
404 | | - # somewhere/mypy/__init__.py and what we want is |
405 | | - # somewhere/lib/mypy. |
406 | | - return subdir |
407 | | - # Default to directory containing this file's parent. |
408 | | - return parent |
409 | | - base = os.path.basename(bin_dir) |
410 | | - dir = os.path.dirname(bin_dir) |
411 | | - if (sys.platform == 'win32' and base.lower() == 'scripts' |
412 | | - and not os.path.isdir(os.path.join(dir, 'typeshed'))): |
413 | | - # Installed, on Windows. |
414 | | - return os.path.join(dir, 'Lib', 'mypy') |
415 | | - elif base == 'scripts': |
416 | | - # Assume that we have a repo check out or unpacked source tarball. |
417 | | - return dir |
418 | | - elif base == 'bin': |
419 | | - # Installed to somewhere (can be under /usr/local or anywhere). |
420 | | - return os.path.join(dir, 'lib', 'mypy') |
421 | | - elif base == 'python3': |
422 | | - # Assume we installed python3 with brew on os x |
423 | | - return os.path.join(os.path.dirname(dir), 'lib', 'mypy') |
424 | | - elif dir.endswith('python-exec'): |
425 | | - # Gentoo uses a python wrapper in /usr/lib to which mypy is a symlink. |
426 | | - return os.path.join(os.path.dirname(dir), 'mypy') |
427 | | - else: |
428 | | - # Don't know where to find the data files! |
429 | | - raise RuntimeError("Broken installation: can't determine base dir") |
| 369 | +def default_data_dir() -> str: |
| 370 | + """Returns directory containing typeshed directory.""" |
| 371 | + return os.path.dirname(__file__) |
430 | 372 |
|
431 | 373 |
|
432 | 374 | def mypy_path() -> List[str]: |
|
0 commit comments