Skip to content

Fail fast if site-packages are in the path #5301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,21 @@ def compute_search_paths(sources: List[BuildSource],
if alt_lib_path:
mypypath.insert(0, alt_lib_path)

package_path = tuple(_get_site_packages_dirs(options.python_executable))
for site_dir in package_path:
assert site_dir not in lib_path
if site_dir in mypypath:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are of course many variant spellings of the same path that won't be caught by this check. I don't think it's necessary to worry about that (normalizing the paths feels kind of expensive), but we shouldn't feel too complacent. :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it won't be perfect, but I think it will catch and help debug some more common cases, as well as avoid crashes in those circumstances.

print("{} is in the MYPYPATH. Please remove it.".format(site_dir), file=sys.stderr)
sys.exit(1)
elif site_dir in python_path:
print("{} is in the PYTHONPATH. Please change directory"
" so it is not.".format(site_dir),
file=sys.stderr)
sys.exit(1)

return SearchPaths(tuple(reversed(python_path)),
tuple(mypypath),
tuple(_get_site_packages_dirs(options.python_executable)),
package_path,
tuple(lib_path))


Expand Down