MCPcopy
hub / github.com/python/mypy / getsyspath

Function getsyspath

mypy/pyinfo.py:40–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38
39
40def getsyspath() -> list[str]:
41 # Do not include things from the standard library
42 # because those should come from typeshed.
43 stdlib_zip = os.path.join(
44 sys.base_exec_prefix,
45 getattr(sys, "platlibdir", "lib"),
46 f"python{sys.version_info.major}{sys.version_info.minor}.zip",
47 )
48 stdlib = sysconfig.get_path("stdlib")
49 stdlib_ext = os.path.join(stdlib, "lib-dynload")
50 excludes = {stdlib_zip, stdlib, stdlib_ext}
51
52 # Drop the first entry of sys.path
53 # - If pyinfo.py is executed as a script (in a subprocess), this is the directory
54 # containing pyinfo.py
55 # - Otherwise, if mypy launched via console script, this is the directory of the script
56 # - Otherwise, if mypy launched via python -m mypy, this is the current directory
57 # In all these cases, it is desirable to drop the first entry
58 # Note that mypy adds the cwd to SearchPaths.python_path, so we still find things on the
59 # cwd consistently (the return value here sets SearchPaths.package_path)
60
61 # Python 3.11 adds a "safe_path" flag wherein Python won't automatically prepend
62 # anything to sys.path. In this case, the first entry of sys.path is no longer special.
63 offset = 0 if sys.version_info >= (3, 11) and sys.flags.safe_path else 1
64
65 abs_sys_path = (os.path.abspath(p) for p in sys.path[offset:])
66 return [p for p in abs_sys_path if p not in excludes]
67
68
69def getsearchdirs() -> tuple[list[str], list[str]]:

Callers 1

getsearchdirsFunction · 0.85

Calls 2

getattrFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…