module documentation
(source)

Low-level infrastructure to find modules.

This builds on fscache.py; find_sources.py builds on top of this.

Class ​Build​Source A single source file.
Class ​Find​Module​Cache Module finder with integrated cache.
Class ​Module​Not​Found​Reason Undocumented
Function add​_py2​_mypypath​_entries Add corresponding @python2 subdirectories to mypypath.
Function compute​_search​_paths Compute the search paths as specified in PEP 561.
Function default​_lib​_path Return default standard library search paths.
Function expand​_site​_packages Expands .pth imports in site-packages directories
Function filter​_redundant​_py2​_dirs If dirs has <dir>/@python2 followed by <dir>, filter out the latter.
Function get​_prefixes Get the sys.base_prefix and sys.prefix for the given python.
Function get​_site​_packages​_dirs Find package directories for given python.
Function highest​_init​_level Compute the highest level where an __init__ file is found.
Function load​_stdlib​_py​_versions Return dict with minimum and maximum Python versions of stdlib modules.
Function matches​_exclude Undocumented
Function mypy​_path Undocumented
Function parse​_version Undocumented
Function typeshed​_py​_version Return Python version used for checking whether module supports typeshed.
Function verify​_module Check that all packages containing id have a __init__ file.
Constant PYTHON2​_STUB​_DIR Undocumented
Constant PYTHON​_EXTENSIONS Undocumented
Variable ​Module​Search​Result Undocumented
Variable ​One​Package​Dir Undocumented
Variable ​Package​Dirs Undocumented
Variable ​Search​Paths Undocumented
Variable ​Stdlib​Versions Undocumented
Function _make​_abspath Take a path and make it absolute relative to root if not already absolute.
Function _parse​_pth​_file Mimics a subset of .pth import hook from Lib/site.py See https://github.com/python/cpython/blob/3.5/Lib/site.py#L146-L185
def add_py2_mypypath_entries(mypypath): (source)

Add corresponding @python2 subdirectories to mypypath.

For each path entry 'x', add 'x/@python2' before 'x' if the latter is a directory.

Parameters
mypypath:List[str]Undocumented
Returns
List[str]Undocumented
def compute_search_paths(sources, options, data_dir, alt_lib_path=None): (source)

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

Parameters
sources:List[BuildSource]Undocumented
options:OptionsUndocumented
data​_dir:strUndocumented
alt​_lib​_path:Optional[str]Undocumented
Returns
SearchPathsUndocumented
def default_lib_path(data_dir, pyversion, custom_typeshed_dir): (source)
Return default standard library search paths.
Parameters
data​_dir:strUndocumented
pyversion:Tuple[int, int]Undocumented
custom​_typeshed​_dir:Optional[str]Undocumented
Returns
List[str]Undocumented
def expand_site_packages(site_packages): (source)
Expands .pth imports in site-packages directories
Parameters
site​_packages:List[str]Undocumented
Returns
Tuple[List[str], List[str]]Undocumented
def filter_redundant_py2_dirs(dirs): (source)
If dirs has <dir>/@python2 followed by <dir>, filter out the latter.
Parameters
dirs:List[str]Undocumented
Returns
List[str]Undocumented
@functools.lru_cache(maxsize=None)
def get_prefixes(python_executable): (source)

Get the sys.base_prefix and sys.prefix for the given python.

This runs a subprocess call to get the prefix paths of the given Python executable. To avoid repeatedly calling a subprocess (which can be slow!) we lru_cache the results.

Parameters
python​_executable:Optional[str]Undocumented
Returns
Tuple[str, str]Undocumented
@functools.lru_cache(maxsize=None)
def get_site_packages_dirs(python_executable): (source)

Find package directories for given python.

This runs a subprocess call, which generates a list of the egg directories, and the site package directories. To avoid repeatedly calling a subprocess (which can be slow!) we lru_cache the results.

Parameters
python​_executable:Optional[str]Undocumented
Returns
Tuple[List[str], List[str]]Undocumented
def highest_init_level(fscache, id, path, prefix): (source)
Compute the highest level where an __init__ file is found.
Parameters
fscache:FileSystemCacheUndocumented
id:strUndocumented
path:strUndocumented
prefix:strUndocumented
Returns
intUndocumented
def load_stdlib_py_versions(custom_typeshed_dir): (source)

Return dict with minimum and maximum Python versions of stdlib modules.

The contents look like {..., 'secrets': ((3, 6), None), 'symbol': ((2, 7), (3, 9)), ...}

None means there is no maximum version.

Parameters
custom​_typeshed​_dir:Optional[str]Undocumented
Returns
StdlibVersionsUndocumented
def matches_exclude(subpath, excludes, fscache, verbose): (source)

Undocumented

Parameters
subpath:strUndocumented
excludes:List[str]Undocumented
fscache:FileSystemCacheUndocumented
verbose:boolUndocumented
Returns
boolUndocumented
def mypy_path(): (source)

Undocumented

Returns
List[str]Undocumented
def parse_version(version): (source)

Undocumented

Parameters
version:strUndocumented
Returns
Tuple[int, int]Undocumented
def typeshed_py_version(options): (source)
Return Python version used for checking whether module supports typeshed.
Parameters
options:OptionsUndocumented
Returns
Tuple[int, int]Undocumented
def verify_module(fscache, id, path, prefix): (source)
Check that all packages containing id have a __init__ file.
Parameters
fscache:FileSystemCacheUndocumented
id:strUndocumented
path:strUndocumented
prefix:strUndocumented
Returns
boolUndocumented
PYTHON2_STUB_DIR: str = (source)

Undocumented

Value
'@python2'
PYTHON_EXTENSIONS: list[str] = (source)

Undocumented

Value
['.pyi', '.py']
ModuleSearchResult = (source)

Undocumented

OnePackageDir = (source)

Undocumented

PackageDirs = (source)

Undocumented

SearchPaths = (source)

Undocumented

StdlibVersions: _TypeAlias = (source)

Undocumented

def _make_abspath(path, root): (source)
Take a path and make it absolute relative to root if not already absolute.
Parameters
path:strUndocumented
root:strUndocumented
Returns
strUndocumented
def _parse_pth_file(dir, pth_filename): (source)
Mimics a subset of .pth import hook from Lib/site.py See https://github.com/python/cpython/blob/3.5/Lib/site.py#L146-L185
Parameters
dir:strUndocumented
pth​_filename:strUndocumented
Returns
Iterator[str]Undocumented