File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 10
10
import sys
11
11
import sysconfig
12
12
13
- if __name__ == '__main__' :
14
- sys .path = sys .path [1 :] # we don't want to pick up mypy.types
15
-
16
13
MYPY = False
17
14
if MYPY :
18
15
from typing import List
@@ -29,10 +26,17 @@ def getsearchdirs():
29
26
)
30
27
stdlib = sysconfig .get_path ("stdlib" )
31
28
stdlib_ext = os .path .join (stdlib , "lib-dynload" )
32
- cwd = os .path .abspath (os .getcwd ())
33
- excludes = set ([cwd , stdlib_zip , stdlib , stdlib_ext ])
34
-
35
- abs_sys_path = (os .path .abspath (p ) for p in sys .path )
29
+ excludes = set ([stdlib_zip , stdlib , stdlib_ext ])
30
+
31
+ # Drop the first entry of sys.path
32
+ # - If pyinfo.py is executed as a script (in a subprocess), this is the directory
33
+ # containing pyinfo.py
34
+ # - Otherwise, if mypy launched via console script, this is the directory of the script
35
+ # - Otherwise, if mypy launched via python -m mypy, this is the current directory
36
+ # In all cases, this is safe to drop
37
+ # Note that mypy adds the cwd to SearchPaths.python_path, so we still find things on the
38
+ # cwd consistently (the return value here sets SearchPaths.package_path)
39
+ abs_sys_path = (os .path .abspath (p ) for p in sys .path [1 :])
36
40
return [p for p in abs_sys_path if p not in excludes ]
37
41
38
42
You can’t perform that action at this time.
0 commit comments