source

utils.source

The file a record is being loaded from, held as scoped context rather than written into the record.

A recipe names its companions by paths relative to itself — a data_file:, an edge_matrix_files: entry, a callable’s module beside the YAML — so whatever resolves them needs the recipe’s directory. That directory is context, never data: resolving the paths to absolute ones in the loaded dict would publish a machine-local path into every dump. The loader states the file for the duration of the construction it starts, and whatever the construction builds reads it back, at any depth, without it being threaded through every constructor.

A :class:contextvars.ContextVar makes the statement scoped: a nested load (a study materialising its experiments, an experiment building its network) sees its own file and restores the outer one on exit, and two threads loading two recipes never see each other’s.

Functions

Name Description
current_source_dir The directory of the recipe being loaded — what its relative paths resolve against — or None outside any load.
current_source_file The absolute path of the recipe being loaded, or None outside any load.
loading_from State that everything constructed inside the block is being loaded from path.

current_source_dir

utils.source.current_source_dir()

The directory of the recipe being loaded — what its relative paths resolve against — or None outside any load.

current_source_file

utils.source.current_source_file()

The absolute path of the recipe being loaded, or None outside any load.

loading_from

utils.source.loading_from(path)

State that everything constructed inside the block is being loaded from path.

The path is resolved to an absolute one once, here. None states nothing: the block sees whatever an enclosing load stated, so a caller that may or may not hold a file wraps its construction the same way in both cases.

Parameters

Name Type Description Default
path str | os.PathLike | None The recipe file being loaded, or None. required

Yields

Name Type Description
str | None The absolute source file in effect inside the block.