Skip to content

Commit 047c2c3

Browse files
emmatypinggvanrossum
authored andcommitted
Fail fast if site-packages are in the path (#5301)
With my refactoring in #5256, I realized that it would be pretty straightforward to give some nicer warnings if site-packages were in any of the PATHs.
1 parent 028bd91 commit 047c2c3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

mypy/build.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,21 @@ def compute_search_paths(sources: List[BuildSource],
275275
if alt_lib_path:
276276
mypypath.insert(0, alt_lib_path)
277277

278+
package_path = tuple(_get_site_packages_dirs(options.python_executable))
279+
for site_dir in package_path:
280+
assert site_dir not in lib_path
281+
if site_dir in mypypath:
282+
print("{} is in the MYPYPATH. Please remove it.".format(site_dir), file=sys.stderr)
283+
sys.exit(1)
284+
elif site_dir in python_path:
285+
print("{} is in the PYTHONPATH. Please change directory"
286+
" so it is not.".format(site_dir),
287+
file=sys.stderr)
288+
sys.exit(1)
289+
278290
return SearchPaths(tuple(reversed(python_path)),
279291
tuple(mypypath),
280-
tuple(_get_site_packages_dirs(options.python_executable)),
292+
package_path,
281293
tuple(lib_path))
282294

283295

0 commit comments

Comments
 (0)