Utilities and Typing¶
Path Utilities¶
pytask.path.import_path(path, root)
¶
Import and return a module from the given path.
The functions are taken from pytest when the import mode is set to importlib. It
was assumed to be the new default import mode but insurmountable tradeoffs caused
the default to be set to prepend. More discussion and information can be found
in #373.
pytask.get_state_of_path(path)
¶
Get state of a path.
A simple function to handle local and remote files.
pytask.path.hash_path(path, modification_time, digest='sha256')
¶
Compute the hash of a file.
The function is connected to a cache that is warmed up with previous hashes during the configuration phase.
Tree Utilities¶
pytask.tree_util.tree_flatten_with_path(tree, /, is_leaf=None)
¶
Flatten a pytask tree into paths, leaves, and structure.
pytask.tree_util.tree_leaves(tree, /, is_leaf=None)
¶
Return the leaves of a pytask tree.
pytask.tree_util.tree_map(func, tree, /, *rests, is_leaf=None)
¶
tree_map(func: Callable[..., PyTree[_T]], tree: dict[_K, PyTree[_T]], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> dict[_K, PyTree[_T]]
tree_map(func: Callable[..., _U], tree: dict[_K, PyTree[_T]], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> dict[_K, PyTree[_U]]
tree_map(func: Callable[..., PyTree[_T]], tree: list[PyTree[_T]], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> list[PyTree[_T]]
tree_map(func: Callable[..., _U], tree: list[PyTree[_T]], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> list[PyTree[_U]]
tree_map(func: Callable[..., PyTree[_T]], tree: tuple[PyTree[_T], ...], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> tuple[PyTree[_T], ...]
tree_map(func: Callable[..., _U], tree: tuple[PyTree[_T], ...], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> tuple[PyTree[_U], ...]
tree_map(func: Callable[..., _U], tree: PyTree[_T], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> PyTree[_U]
Apply a function to each leaf of a pytask tree.
pytask.tree_util.tree_map_with_path(func, tree, /, *rests, is_leaf=None)
¶
tree_map_with_path(func: Callable[..., PyTree[_T]], tree: dict[_K, PyTree[_T]], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> dict[_K, PyTree[_T]]
tree_map_with_path(func: Callable[..., _U], tree: dict[_K, PyTree[_T]], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> dict[_K, PyTree[_U]]
tree_map_with_path(func: Callable[..., PyTree[_T]], tree: list[PyTree[_T]], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> list[PyTree[_T]]
tree_map_with_path(func: Callable[..., _U], tree: list[PyTree[_T]], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> list[PyTree[_U]]
tree_map_with_path(func: Callable[..., PyTree[_T]], tree: tuple[PyTree[_T], ...], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> tuple[PyTree[_T], ...]
tree_map_with_path(func: Callable[..., _U], tree: tuple[PyTree[_T], ...], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> tuple[PyTree[_U], ...]
tree_map_with_path(func: Callable[..., _U], tree: PyTree[_T], /, *rests: PyTree[Any], is_leaf: Callable[[Any], bool] | None = None) -> PyTree[_U]
Apply a function to each leaf and pass the leaf path.
pytask.tree_util.tree_structure(tree, /, is_leaf=None)
¶
Return the tree structure of a pytask tree.
Typing Helpers¶
pytask.Product = ProductType()
module-attribute
¶
ProductType: A singleton to mark products in annotations.
pytask.is_task_function(obj)
¶
Check if an object could be decorated as a task function.