livery.extensions.python._parse¶
livery.extensions.python._parse ¶
Parse each python source once, and say what it references.
The layering phase reads every python source through this module: the
python extension's references answer and its layering steps,
private-reaches, runner-terminal and declared-imports. parsed_source
parses a file once for a given content, memoised by the file's path,
size and modification time, so the steps, which run in one process,
read one tree, and an unchanged file is never parsed twice.
parsed_modules hands a rule the sources in its scope, every one or
the files a narrowed run selects, RuleContext is what a rule judges,
and graph_changed is what each step's inputs widen on.
Classes:
| Name | Description |
|---|---|
Parsed |
One parsed source. |
RuleContext |
What a layering rule over the python sources judges: the workspace and a scope. |
ParsedModule |
One python source as a rule sees it. |
Functions:
| Name | Description |
|---|---|
parsed_source |
path parsed once for its content; None when it does not parse. |
references_of |
Every dotted name tree imports, in source order, once for each way. |
parsed_modules |
Every python source the workspace holds, or the named ones, parsed once. |
dotted_name |
The dotted module path of source, a file under the |
graph_changed |
Whether a contract, a native manifest or a root |
Parsed
dataclass
¶
Parsed(tree: Module, references: tuple[ReferencedName, ...])
One parsed source.
Attributes:
| Name | Type | Description |
|---|---|---|
tree |
Module
|
The module's syntax tree. |
references |
tuple[ReferencedName, ...]
|
Every dotted name it imports, once for each place it imports it from: at import time or lazily, and under which guard. |
RuleContext
dataclass
¶
What a layering rule over the python sources judges: the workspace and a scope.
Attributes:
| Name | Type | Description |
|---|---|---|
root |
Path
|
The workspace root. |
packages |
tuple[Package, ...]
|
Every package the workspace carries. |
files |
frozenset[str] | None
|
The root-relative sources the run judges; None for every one. |
Methods:
| Name | Description |
|---|---|
packages_in_scope |
The packages holding a source this run judges, every one without a scope. |
packages_in_scope ¶
The packages holding a source this run judges, every one without a scope.
Source code in packages/extensions/python/src/livery/extensions/python/_parse.py
ParsedModule
dataclass
¶
ParsedModule(package: Package | None, path: Path, relative: str, area: str, dotted: str, tree: Module)
One python source as a rule sees it.
Attributes:
| Name | Type | Description |
|---|---|---|
package |
Package | None
|
The package the file belongs to; None for the root's
own |
path |
Path
|
The file, absolute. |
relative |
str
|
The file, relative to the workspace root, posix. |
area |
str
|
|
dotted |
str
|
The module's dotted path under |
tree |
Module
|
The syntax tree. |
parsed_source ¶
path parsed once for its content; None when it does not parse.
The memo key is the path with its size and modification time, so an edited file parses again and an unchanged one never does.
Source code in packages/extensions/python/src/livery/extensions/python/_parse.py
references_of ¶
references_of(tree: Module) -> tuple[ReferencedName, ...]
Every dotted name tree imports, in source order, once for each way.
A from import references the module and each name imported
from it: under a PEP 420 namespace the module alone can be the
namespace, and the package that owns the code is one segment
further down. A name imported twice the same way is listed once. A
relative import names the source's own package and is left out.
An import inside a function or a method body is lazy: importing the
module does not run it. One in the body of if TYPE_CHECKING: is
made by a type checker alone. One in the body of a try with a
handler for ImportError, ModuleNotFoundError or every
exception is optional: the source runs without the module.
Only a statement imports, so the walk reads the statements and never descends into an expression.
Source code in packages/extensions/python/src/livery/extensions/python/_parse.py
parsed_modules ¶
parsed_modules(root: Path, packages: tuple[Package, ...], files: frozenset[str] | None = None) -> tuple[ParsedModule, ...]
Every python source the workspace holds, or the named ones, parsed once.
The root's own tasks.py, then each package's src and
tests trees in package order. files keeps the root-relative
sources it names, and a named file that no longer exists is left
out. A file that does not parse is left out: the syntax gate names
it.
Source code in packages/extensions/python/src/livery/extensions/python/_parse.py
dotted_name ¶
The dotted module path of source, a file under the src tree src.
livery/forge/_dev/__init__.py under src is livery.forge._dev.
Source code in packages/extensions/python/src/livery/extensions/python/_parse.py
graph_changed ¶
Whether a contract, a native manifest or a root src/ changed.
The layering steps' inputs widen on them: the distributions' roots
and declarations come from the manifests, and the allowances from
the root contract, so a change there judges every source, as the
base's layering steps do. The workshop answers it
(livery.workshop.graph_changed); a step's widen reference
names the extension's own code, so this function hands it on.