pytest_pep723.extract

Parse PEP 723 inline script metadata and extract imports from Python files.

Attributes

Functions

has_pep723_block(→ bool)

Check whether source contains a PEP 723 script metadata block.

parse_pep723_deps(→ set[str])

Extract normalized package names from a PEP 723 script block.

extract_imports(→ set[str])

Extract all top-level package names from import statements in source.

normalize_import_to_pkg(→ str)

Map an import name to the expected PyPI package name.

check_script() → list[str])

Check a PEP 723 script for uncovered imports.

find_pep723_scripts(→ list[pathlib.Path])

Recursively find .py files under root with PEP 723 script blocks.

Module Contents

pytest_pep723.extract.IMPORT_TO_PKG: dict[str, str][source]
pytest_pep723.extract.STDLIB: frozenset[str][source]
pytest_pep723.extract.has_pep723_block(source: str) bool[source]

Check whether source contains a PEP 723 script metadata block.

pytest_pep723.extract.parse_pep723_deps(source: str) set[str][source]

Extract normalized package names from a PEP 723 script block.

Returns the set of lowercased package names (version specs stripped).

pytest_pep723.extract.extract_imports(source: str) set[str][source]

Extract all top-level package names from import statements in source.

pytest_pep723.extract.normalize_import_to_pkg(imp: str) str[source]

Map an import name to the expected PyPI package name.

pytest_pep723.extract.check_script(source: str, ignore_imports: frozenset[str] = frozenset()) list[str][source]

Check a PEP 723 script for uncovered imports.

Returns a list of import names that are not covered by the declared inline dependencies, stdlib, or the ignore set.

pytest_pep723.extract.find_pep723_scripts(root: pathlib.Path) list[pathlib.Path][source]

Recursively find .py files under root with PEP 723 script blocks.