schedr.runner.parse

Parse mode: import DAG files by their ordinary names, and report the DAGs they define.

A file is imported as Python would (team/sync.py is team.sync), each in a process of its own, and a task’s process imports it the same way (decision 326). Files that define no DAG report none; a file that raises reports an import error and doesn’t stop the others.

schedr.runner.parse.TRACEBACK_LINES = 20

How many traceback lines an import error keeps.

schedr.runner.parse.module_name(root, path)

The name a DAG file is imported under: the ordinary one, from the root it is in.

team/sync.py is team.sync, so relative imports, __init__.py, cycles and sys.modules work as Python’s do (decision 326). The root is a label, not a package.

Parameters:
  • root (str) – The DAG root’s name.

  • path (str) – The file’s path relative to the root.

Returns:

The module’s name.

Raises:

ImportError – For a path with no name of its own (a.b.py would mean a/b.py).

Return type:

str

schedr.runner.parse.import_dag_entries(root, root_dir, path)

Imports one DAG file and returns the DAGs it defined, with their task functions.

Parameters:
  • root (str) – The DAG root’s name.

  • root_dir (Path) – The root’s directory.

  • path (str) – The file’s path relative to the root.

Returns:

The DAGs, in definition order (empty for a helper module).

Raises:

BaseException – Whatever importing the file raised (its partial DAGs are dropped).

Return type:

list[DefinedDag]

schedr.runner.parse.import_dag_file(root, root_dir, path)

Imports one DAG file and returns the DAGs it defined.

Parameters:
  • root (str) – The DAG root’s name.

  • root_dir (Path) – The root’s directory.

  • path (str) – The file’s path relative to the root.

Returns:

The DAGs, in definition order (empty for a helper module).

Return type:

list[Dag]

schedr.runner.parse.import_error(error)

An import error (or a task’s failure) as sent to the agent.

The traceback starts at the user’s code: the runner’s own frames and importlib’s before it are left out (all of them are kept when every frame is schedr’s).

Parameters:

error (BaseException) – The exception.

Returns:

Its class name, message and the last TRACEBACK_LINES lines of the traceback.

Return type:

dict[str, str]

schedr.runner.parse.file_result(root, root_dir, path)

Imports one file and builds its file_parsed message.

Parameters:
  • root (str) – The DAG root’s name.

  • root_dir (Path) – The root’s directory.

  • path (str) – The file’s path relative to the root.

Returns:

The message, with the DAG JSON of each DAG, or the import error, and the warnings importing it raised (Category: message; a TypingHint or DagHint always, others as the interpreter’s warning filters let them through).

Return type:

dict[str, Any]

schedr.runner.parse.own_connections(root, path)

The connections the file just imported defines itself, as reported.

A module it imports may define connections too, reported when that module’s own file is parsed (as its DAGs, B110).

Parameters:
  • root (str) – The DAG root’s name.

  • path (str) – The file’s path relative to the root.

Returns:

Each connection’s {"name", "params"}, in definition order.

Raises:

ValueError – When the file defines two connections of one name.

Return type:

list[dict[str, Any]]

schedr.runner.parse.extend_sys_path(entries)

Makes these directories the DAG roots on sys.path, first and in this order.

Modules found there are imported from their source, never from bytecode (B59). A name that can’t be told apart fails what uses it, saying why (decision 328). In a process used for several roots (a test’s), what the earlier ones gave is forgotten.

Parameters:

entries (list[str]) – The directories (every DAG root).

Return type:

None

schedr.runner.parse.run_parse(channel, request)

Handles a parse request: imports each file, reporting progress and results.

Parameters:
  • channel (Channel) – The channel to the agent.

  • request (dict[str, Any]) – The parse message (root, root directory, files, sys.path entries).

Return type:

None