From 783faad1c4022948d75b10921e8d8bcbd0c42264 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Fri, 29 Jun 2018 17:13:56 -0400 Subject: [PATCH 1/3] Fail fast if site-packages are in the path --- mypy/build.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mypy/build.py b/mypy/build.py index a24a27bf2dae..dd84a4a687fd 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -275,9 +275,23 @@ 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 in package_path: + if site in mypypath: + print("site-packages is in the MYPYPATH. Please remove it.", file=sys.stderr) + elif site in python_path: + print("site-packages is in the PYTHONPAT. Please change directory so it is not.", + file=sys.stderr) + elif site in lib_path: + print("this should never, ever happen", file=sys.stderr) + else: + # this site not in any of the other paths, we are safe. + continue + sys.exit(1) + return SearchPaths(tuple(reversed(python_path)), tuple(mypypath), - tuple(_get_site_packages_dirs(options.python_executable)), + package_path, tuple(lib_path)) From 01a6f4bc6fb0d190e408a9a6ddd9dce9f0cd6113 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Fri, 29 Jun 2018 18:36:37 -0400 Subject: [PATCH 2/3] Respond to feedback --- mypy/build.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index dd84a4a687fd..da9db5aff2cb 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -276,19 +276,17 @@ def compute_search_paths(sources: List[BuildSource], mypypath.insert(0, alt_lib_path) package_path = tuple(_get_site_packages_dirs(options.python_executable)) - for site in package_path: - if site in mypypath: - print("site-packages is in the MYPYPATH. Please remove it.", file=sys.stderr) - elif site in python_path: - print("site-packages is in the PYTHONPAT. Please change directory so it is not.", + for site_dir in package_path: + assert site_dir not in lib_path + if site_dir in mypypath: + print("{} is in the MYPYPATH. Please remove it.".format(site_dir), file=sys.stderr) + elif site_dir in python_path: + print("{} is in the PYTHONPATH. Please change directory so it is not.".format(site_dir), file=sys.stderr) - elif site in lib_path: - print("this should never, ever happen", file=sys.stderr) else: # this site not in any of the other paths, we are safe. continue sys.exit(1) - return SearchPaths(tuple(reversed(python_path)), tuple(mypypath), package_path, From df344738dd261846523d431e8d28a9db2d88b528 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sat, 30 Jun 2018 03:33:15 -0400 Subject: [PATCH 3/3] Make code cleaner --- mypy/build.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index da9db5aff2cb..783a10aad532 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -280,13 +280,13 @@ def compute_search_paths(sources: List[BuildSource], assert site_dir not in lib_path if site_dir in mypypath: 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), + print("{} is in the PYTHONPATH. Please change directory" + " so it is not.".format(site_dir), file=sys.stderr) - else: - # this site not in any of the other paths, we are safe. - continue - sys.exit(1) + sys.exit(1) + return SearchPaths(tuple(reversed(python_path)), tuple(mypypath), package_path,