Skip to content

Commit 6c409b4

Browse files
emmatypingilevkivskyi
authored andcommitted
Fix finding typeshed user install on Windows (#3991)
Python 3.5+ installs to `%APPDATA%\python\PythonXY`. Mypy, when installed as user, installs typeshed to `%APPDATA%\python\lib\mypy`. This fixes the issues with resolving the path to typeshed. Additionally, more debug information is added to the error message to assist in debugging issues like this in the future. Fixes #3988
1 parent 2bd11f6 commit 6c409b4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mypy/build.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,13 @@ def default_data_dir(bin_dir: Optional[str]) -> str:
223223
# or .../blah/lib64/python3.N/dist-packages/mypy/build.py (Gentoo)
224224
# or .../blah/lib/site-packages/mypy/build.py (Windows)
225225
# blah may be a virtualenv or /usr/local. We want .../blah/lib/mypy.
226+
# On Windows, if the install is .../python/PythonXY/site-packages, we want
227+
# .../python/lib/mypy
226228
lib = parent
227229
for i in range(2):
228230
lib = os.path.dirname(lib)
229-
if os.path.basename(lib) in ('lib', 'lib32', 'lib64'):
231+
if os.path.basename(lib) in ('lib', 'lib32', 'lib64') \
232+
or os.path.basename(lib).startswith('python'):
230233
return os.path.join(os.path.dirname(lib), 'lib/mypy')
231234
subdir = os.path.join(parent, 'lib', 'mypy')
232235
if os.path.isdir(subdir):
@@ -299,9 +302,10 @@ def default_lib_path(data_dir: str,
299302
if sys.platform != 'win32':
300303
path.append('/usr/local/lib/mypy')
301304
if not path:
302-
print("Could not resolve typeshed subdirectories. If you are using MyPy"
303-
"from source, you need to run \"git submodule --init update\"."
304-
"Otherwise your MyPy install is broken.", file=sys.stderr)
305+
print("Could not resolve typeshed subdirectories. If you are using mypy\n"
306+
"from source, you need to run \"git submodule --init update\".\n"
307+
"Otherwise your mypy install is broken.\nPython executable is located at "
308+
"{0}.\nMypy located at {1}".format(sys.executable, data_dir), file=sys.stderr)
305309
sys.exit(1)
306310
return path
307311

0 commit comments

Comments
 (0)