livery.extensions.python._declared¶
livery.extensions.python._declared ¶
The declared-imports rule: a package's source imports what its manifest declares.
At import time, a module under a package's src imports only the
standard library, the workspace's own members, and the distributions
the package's pyproject.toml declares in [project.dependencies].
Inside a function or a method it may also import a distribution an
optional extra declares, since importing the module does not run that
import. An import under TYPE_CHECKING, or in a try that handles
ImportError, is not judged: no run makes the first, and the source
runs without the second.
A module a program loads as a plugin, named in one of the program's
entry-point groups (footman.tasks and footman.builtin for the
runner, pytest11 for pytest), may also import what that program
brings: its distribution and the distributions it requires. The
program is present whenever such a module runs. A name another member
owns is left to the sibling-references step, which judges the edges
between members.
Which distribution provides a module is read from the metadata of the distributions the workspace's environment installed, so a module that no installed distribution provides refuses, naming it.
The rule is a step of the layering phase,
[phases.layering.declared-imports], over each python package's
references answer: the sources a narrowed run reaches, every one
otherwise.
Classes:
| Name | Description |
|---|---|
Manifest |
What a package's |
Functions:
| Name | Description |
|---|---|
declared_imports |
The step: refuse each import that no declaration of its package accounts for. |
manifest |
What package's |
problems |
Each import no declaration accounts for, in package and source order. |
judged |
What source imports that declared does not account for, one line each. |
Attributes:
| Name | Type | Description |
|---|---|---|
DEPENDENCIES |
|
Manifest
dataclass
¶
Manifest(path: str, dependencies: frozenset[str], extras: Mapping[str, frozenset[str]], plugins: Mapping[str, frozenset[str]])
What a package's pyproject.toml declares, as the rule reads it.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
The file, relative to the workspace root, posix. |
dependencies |
frozenset[str]
|
The distributions |
extras |
Mapping[str, frozenset[str]]
|
Each optional extra, to the distributions it names, normalized. |
plugins |
Mapping[str, frozenset[str]]
|
Each module the package names in a plugin entry-point group, to the distributions of the programs that load it. |
Methods:
| Name | Description |
|---|---|
loaded_by |
The programs that load module as a plugin, or a package above it. |
extra_naming |
The first optional extra naming one of distributions; empty for none. |
loaded_by ¶
The programs that load module as a plugin, or a package above it.
Source code in packages/extensions/python/src/livery/extensions/python/_declared.py
extra_naming ¶
The first optional extra naming one of distributions; empty for none.
Source code in packages/extensions/python/src/livery/extensions/python/_declared.py
declared_imports ¶
declared_imports(ctx: PhaseContext) -> None
The step: refuse each import that no declaration of its package accounts for.
The sources the run reaches (livery.workshop.selected_files) are judged; every source when the run knows nothing of what changed.
Source code in packages/extensions/python/src/livery/extensions/python/_declared.py
manifest ¶
What package's pyproject.toml declares that the rule reads.
Source code in packages/extensions/python/src/livery/extensions/python/_declared.py
problems ¶
problems(context: RuleContext) -> list[str]
Each import no declaration accounts for, in package and source order.
A package that holds the python extension is judged, each of its
sources under src that the run reaches, as this extension's
references answer records them.
Source code in packages/extensions/python/src/livery/extensions/python/_declared.py
judged ¶
judged(source: SourceReferences, declared: Manifest, around: Neighbours) -> list[str]
What source imports that declared does not account for, one line each.
Import-time references are judged before lazy ones, and each distribution is named once per source, at the first reference that needs it. A namespace several distributions share is judged through the names under it that the source references, since those decide which distribution the source needs.