Skip to content

Commit 9615b9e

Browse files
emmatypingilevkivskyi
authored andcommitted
Support user install on Windows. (#4005)
On Windows, the usual install paths are `sys.prefix/Lib/mypy` for a global install. For user installs, the path is `site.getuserbase()/lib/mypy`. We also fall back to the old method of installation due to the data dir being put in the package directory on an egg install. This restores the usual data directory resolution on other platforms. Correctly fixes #3988, and keeps other platforms working.
1 parent 79bce27 commit 9615b9e

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
@@ -17,6 +17,7 @@
1717
import json
1818
import os.path
1919
import re
20+
import site
2021
import sys
2122
import time
2223
from os.path import dirname, basename
@@ -213,6 +214,12 @@ def default_data_dir(bin_dir: Optional[str]) -> str:
213214
bin_dir: directory containing the mypy script
214215
"""
215216
if not bin_dir:
217+
if os.name == 'nt':
218+
prefixes = [os.path.join(sys.prefix, 'Lib'), os.path.join(site.getuserbase(), 'lib')]
219+
for parent in prefixes:
220+
data_dir = os.path.join(parent, 'mypy')
221+
if os.path.exists(data_dir):
222+
return data_dir
216223
mypy_package = os.path.dirname(__file__)
217224
parent = os.path.dirname(mypy_package)
218225
if (os.path.basename(parent) == 'site-packages' or
@@ -223,13 +230,10 @@ def default_data_dir(bin_dir: Optional[str]) -> str:
223230
# or .../blah/lib64/python3.N/dist-packages/mypy/build.py (Gentoo)
224231
# or .../blah/lib/site-packages/mypy/build.py (Windows)
225232
# 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
228233
lib = parent
229234
for i in range(2):
230235
lib = os.path.dirname(lib)
231-
if os.path.basename(lib) in ('lib', 'lib32', 'lib64') \
232-
or os.path.basename(lib).startswith('python'):
236+
if os.path.basename(lib) in ('lib', 'lib32', 'lib64'):
233237
return os.path.join(os.path.dirname(lib), 'lib/mypy')
234238
subdir = os.path.join(parent, 'lib', 'mypy')
235239
if os.path.isdir(subdir):

0 commit comments

Comments
 (0)