Compute the search paths as specified in PEP 561. There are the following 4 members created: - User code (from `sources`) - MYPYPATH (set either via config or environment variable) - installed package directories (which will later be split into stub-only and inline) - typeshed
(
sources: list[BuildSource], options: Options, data_dir: str, alt_lib_path: str | None = None
)
| 882 | |
| 883 | |
| 884 | def compute_search_paths( |
| 885 | sources: list[BuildSource], options: Options, data_dir: str, alt_lib_path: str | None = None |
| 886 | ) -> SearchPaths: |
| 887 | """Compute the search paths as specified in PEP 561. |
| 888 | |
| 889 | There are the following 4 members created: |
| 890 | - User code (from `sources`) |
| 891 | - MYPYPATH (set either via config or environment variable) |
| 892 | - installed package directories (which will later be split into stub-only and inline) |
| 893 | - typeshed |
| 894 | """ |
| 895 | # Determine the default module search path. |
| 896 | lib_path = collections.deque( |
| 897 | default_lib_path( |
| 898 | data_dir, options.python_version, custom_typeshed_dir=options.custom_typeshed_dir |
| 899 | ) |
| 900 | ) |
| 901 | |
| 902 | if options.use_builtins_fixtures: |
| 903 | # Use stub builtins (to speed up test cases and to make them easier to |
| 904 | # debug). This is a test-only feature, so assume our files are laid out |
| 905 | # as in the source tree. |
| 906 | # We also need to allow overriding where to look for it. Argh. |
| 907 | root_dir = os.getenv("MYPY_TEST_PREFIX", None) |
| 908 | if not root_dir: |
| 909 | root_dir = os.path.dirname(os.path.dirname(__file__)) |
| 910 | root_dir = os.path.abspath(root_dir) |
| 911 | lib_path.appendleft(os.path.join(root_dir, "test-data", "unit", "lib-stub")) |
| 912 | # alt_lib_path is used by some tests to bypass the normal lib_path mechanics. |
| 913 | # If we don't have one, grab directories of source files. |
| 914 | python_path: list[str] = [] |
| 915 | if not alt_lib_path: |
| 916 | for source in sources: |
| 917 | # Include directory of the program file in the module search path. |
| 918 | if source.base_dir: |
| 919 | dir = source.base_dir |
| 920 | if dir not in python_path: |
| 921 | python_path.append(dir) |
| 922 | |
| 923 | # Do this even if running as a file, for sanity (mainly because with |
| 924 | # multiple builds, there could be a mix of files/modules, so its easier |
| 925 | # to just define the semantics that we always add the current director |
| 926 | # to the lib_path |
| 927 | # TODO: Don't do this in some cases; for motivation see see |
| 928 | # https://github.com/python/mypy/issues/4195#issuecomment-341915031 |
| 929 | if options.bazel: |
| 930 | dir = "." |
| 931 | else: |
| 932 | dir = os.getcwd() |
| 933 | if dir not in lib_path: |
| 934 | python_path.insert(0, dir) |
| 935 | |
| 936 | # Start with a MYPYPATH environment variable at the front of the mypy_path, if defined. |
| 937 | mypypath = mypy_path() |
| 938 | |
| 939 | # Add a config-defined mypy path. |
| 940 | mypypath.extend(options.mypy_path) |
| 941 |
no test coverage detected
searching dependent graphs…