schedr.runner.sources¶
DAG roots are imported from their source, never from bytecode (B59).
Python’s source loader reuses a .pyc whose recorded modification time (whole seconds) and
size match the source. git-sync switching a root to a new revision can change a file without
changing either (an edit of the same length within the same second), so a fresh runner would
run the old code while the agent hashed, and reports, the new. Code under a DAG root is
compiled from its source at each import instead, and no bytecode is written there; other
imports (schedr, the libraries) keep their caches.
- schedr.runner.sources.IMPORTING: ContextVar = <ContextVar name='schedr_importing' default=None>¶
The DAG root’s file whose top level is running, if one is.
- schedr.runner.sources.search_for_clashes(roots, others)¶
Sets the DAG roots whose names
clash()looks at, forgetting what it knew.- Parameters:
roots (list[str]) – The DAG roots, in
sys.pathorder.others (list[str]) – The rest of
sys.path.
- Return type:
None
- schedr.runner.sources.clash(name)¶
Why a top-level name can’t be told apart: in two roots, or also a library’s.
Only what uses one fails (decision 328): a stray
queue.pymust not stop a root’s other files, nor a deployment’s tasks. Each name is looked at when first imported: a process imports a few, and every file and every task starts one, whatever the size of the root.- Parameters:
name (str) – The name, without dots.
- Returns:
What to tell the author, or
Noneif the name can be used.- Return type:
str | None
- class schedr.runner.sources.NameGuard¶
Bases:
objectA meta path finder: a clashing name is never a DAG root’s, for a library importing it.
A root’s own files importing one fail when compiled (see
SourceOnlyLoader), so this leaves libraries working whatever a root holds, under any start method.- static find_spec(name, path=None, target=None)¶
The library’s module of a clashing name;
Nonefor any other name.- Parameters:
name (str) – The module’s name.
path (object) – Its parent’s search path.
target (ModuleType | None) – The module being reloaded.
- Returns:
the next finders then look.
- Return type:
Its spec, or
None- Raises:
ModuleNotFoundError – For a clashing name that no library has.
- class schedr.runner.sources.SourceOnlyLoader(fullname, path)¶
Bases:
SourceFileLoaderA source file loader that compiles the source at every import, never using bytecode.
- exec_module(module)¶
Runs the module, saying so: the
Dagits top level enters belongs to it.- Parameters:
module (ModuleType) – The module being imported.
- Return type:
None
- get_code(fullname)¶
The module’s code, compiled from its source now.
- Parameters:
fullname (str) – The module’s name.
- Returns:
The compiled code.
- Return type:
CodeType
- schedr.runner.sources.registered_roots()¶
The DAG root directories registered so far, in their order on
sys.path.- Returns:
The directories.
- Return type:
list[str]
- schedr.runner.sources.forgotten_roots(kept)¶
Forgets the DAG roots registered so far but these.
- Parameters:
kept (list[str]) – The directories to keep, as absolute paths.
- Returns:
The ones forgotten.
- Return type:
set[str]
- schedr.runner.sources.import_from_source(roots)¶
Makes imports from these DAG root directories compile their source (see the module).
- Parameters:
roots (list[str]) – The directories, as on
sys.path.- Return type:
None