oct
Loading...
Searching...
No Matches
oct.testing.cache._ModuleIndex Class Reference

Public Member Functions

None __init__ (self, Sequence[Path] roots)
str identify (self, Path path)
bool inside_workspace (self, Path path)
str|None hash_of (self, Path path)
tuple[str, tuple[Path,...]] resolve (self, str dotted)
tuple[str, tuple[Path,...]] resolve_relative (self, Path origin, int level, str module, Sequence[str] names)
tuple[tuple[Path,...], tuple[str,...], bool] imports_of (self, Path path)
tuple[tuple[Path,...], tuple[str,...]]|None closure (self, Path path)

Protected Member Functions

Path|None _common_anchor (self)
tuple[str, Path|None] _top_location (self, str top)
tuple[str, Path|None] _top_from_importlib (self, str top)
tuple[tuple[Path,...], tuple[str,...], bool] _read_imports (self, Path path)

Protected Attributes

 _roots
Path|None _anchor = self._common_anchor()
dict _top = {}
dict _resolved = {}
dict[ _imports
dict _hashes = {}

Detailed Description

Resolve dotted module names to workspace files, by path.

The resolution is deliberately FILESYSTEM-first over the declared
workspace roots and only then ``importlib``: in a worktree the
editable install can point at another checkout (the F17 shadow
class), and a key built from another checkout's bytes would be a
silent wrong answer. ``importlib`` is consulted for the top-level
name alone, which is what tells stdlib and site-packages apart
from a module that simply does not exist.

No module is ever IMPORTED here: importing a test's dependencies
at collection time would run their side effects.

Definition at line 383 of file cache.py.

Constructor & Destructor Documentation

◆ __init__()

None oct.testing.cache._ModuleIndex.__init__ ( self,
Sequence[Path] roots )

Definition at line 398 of file cache.py.

Member Function Documentation

◆ _common_anchor()

Path | None oct.testing.cache._ModuleIndex._common_anchor ( self)
protected
The deepest directory every workspace root sits under.

Definition at line 411 of file cache.py.

◆ _read_imports()

tuple[tuple[Path, ...], tuple[str, ...], bool] oct.testing.cache._ModuleIndex._read_imports ( self,
Path path )
protected
The uncached half of :meth:`imports_of`.

Definition at line 618 of file cache.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _top_from_importlib()

tuple[str, Path | None] oct.testing.cache._ModuleIndex._top_from_importlib ( self,
str top )
protected
Classify a top-level name the workspace roots do not hold.

Definition at line 472 of file cache.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _top_location()

tuple[str, Path | None] oct.testing.cache._ModuleIndex._top_location ( self,
str top )
protected
Locate a TOP-LEVEL name: a workspace root, else importlib.

Definition at line 450 of file cache.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ closure()

tuple[tuple[Path, ...], tuple[str, ...]] | None oct.testing.cache._ModuleIndex.closure ( self,
Path path )
Everything reachable from *path*'s imports.

Returns
-------
tuple | None
    ``(files, absent)``: the workspace files whose bytes join
    the key, and the top-level names that resolved NOWHERE and
    whose absence joins it instead. The file itself is not in
    *files* - it is hashed separately as the key's first input.
    ``None`` means a first-party input could not be resolved or
    read, which fails the whole key closed.

Definition at line 670 of file cache.py.

Here is the call graph for this function:

◆ hash_of()

str | None oct.testing.cache._ModuleIndex.hash_of ( self,
Path path )
SHA-256 of *path*'s bytes, memoised; None when unreadable.

Definition at line 440 of file cache.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ identify()

str oct.testing.cache._ModuleIndex.identify ( self,
Path path )
A stable, anchor-relative identifier for *path*.

Definition at line 420 of file cache.py.

◆ imports_of()

tuple[tuple[Path, ...], tuple[str, ...], bool] oct.testing.cache._ModuleIndex.imports_of ( self,
Path path )
Every workspace file *path*'s imports reach.

Returns
-------
tuple
    ``(files, absent, resolved)``. *absent* names resolved
    nowhere and are recorded in the key rather than hashed.
    *resolved* is False when the module does not parse or when
    a relative import escapes the workspace - the fail-closed
    conditions that make a key ``None``.

Definition at line 593 of file cache.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ inside_workspace()

bool oct.testing.cache._ModuleIndex.inside_workspace ( self,
Path path )
True when *path* lives under one of the workspace roots.

Definition at line 429 of file cache.py.

Here is the caller graph for this function:

◆ resolve()

tuple[str, tuple[Path, ...]] oct.testing.cache._ModuleIndex.resolve ( self,
str dotted )
Resolve *dotted* to the source files importing it executes.

Returns
-------
tuple
    ``(kind, files)`` where *kind* is one of
    :data:`KIND_WORKSPACE`, :data:`KIND_EXTERNAL` or
    :data:`KIND_MISSING`. A workspace package contributes every
    ``__init__.py`` on the way down, because importing the leaf
    executes all of them.

Definition at line 502 of file cache.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolve_relative()

tuple[str, tuple[Path, ...]] oct.testing.cache._ModuleIndex.resolve_relative ( self,
Path origin,
int level,
str module,
Sequence[str] names )
Resolve a ``from .`` import against the filesystem.

Relative imports are resolved by PATH rather than by package
name: a test root that is not a package has no importable
dotted name, and reconstructing one would refuse a file the
interpreter imports happily.

Definition at line 554 of file cache.py.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _anchor

oct.testing.cache._ModuleIndex._anchor = self._common_anchor()
protected

Definition at line 402 of file cache.py.

◆ _hashes

dict oct.testing.cache._ModuleIndex._hashes = {}
protected

Definition at line 408 of file cache.py.

◆ _imports

dict[ oct.testing.cache._ModuleIndex._imports
protected

Definition at line 405 of file cache.py.

◆ _resolved

dict oct.testing.cache._ModuleIndex._resolved = {}
protected

Definition at line 404 of file cache.py.

◆ _roots

oct.testing.cache._ModuleIndex._roots
protected
Initial value:
= tuple(dict.fromkeys(
Path(root).resolve() for root in roots
))

Definition at line 399 of file cache.py.

◆ _top

dict oct.testing.cache._ModuleIndex._top = {}
protected

Definition at line 403 of file cache.py.


The documentation for this class was generated from the following file:
  • G:/PythonApps/option_c/oct/oct/testing/cache.py