pydoit_nb.config_handling#
Tools for working with configuration
insert_path_prefix#
- insert_path_prefix(config, prefix)[source]#
Insert path prefix into config attributes
This adds the prefix
prefixto any attributes ofconfigwhich arePath- Parameters:
config (
typing.TypeVar(AI, bound=attr.AttrsInstance)) – Config to updateprefix (
pathlib.Path) – Prefix to add to paths
- Returns:
typing.TypeVar(AI, bound=attr.AttrsInstance) – Updatedconfig
iterable_values_are_updatable#
- iterable_values_are_updatable(value)[source]#
Determine whether an iterable’s values are updatable by
insert_path_prefix().- Parameters:
value (
collections.abc.Iterable[typing.Any]) – Value to check.- Returns:
bool–Trueifvalue’s elements can be updated byupdate_attr_value(),Falseotherwise.
update_attr_value#
- update_attr_value(value, prefix)[source]#
Update the attribute value if it is
Pathto include the prefixThe prefix is taken from the outer scope
- Parameters:
value (
typing.Union[attr.AttrsInstance,pathlib.Path,typing.TypeVar(T)]) – Value to updateprefix (
pathlib.Path) – Prefix to insert before paths ifvalueis an instance ofPath
- Returns:
typing.Union[attr.AttrsInstance,pathlib.Path,typing.TypeVar(T)] – Updated value
get_step_config_ids#
- get_step_config_ids(step_configs)[source]#
Get available config IDs from an iterable of step configurations
- Parameters:
step_configs (
collections.abc.Iterable[pydoit_nb.typing.NotebookConfigLike]) – Step configurations from which to retrieve the step config IDs- Returns:
list[str] – Step config ID from each step config instep_configs- Raises:
AttributeError – Any object in
step_configsis missing a “step_config_id” attribute.
get_config_for_step_id#
- get_config_for_step_id(config, step, step_config_id)[source]#
Get configuration for a specific value of step config ID for a specific step
This will fail if
stepisn’t a part ofconfig- Parameters:
config (
typing.Any) – Config from which to retrieve the step configstep (
str) – Step inconfigin which to find a step that has the a step config ID equal tostep_config_idstep_config_id (
str) – Value that the retrieved configuration’sstep_config_idmust match
- Returns:
typing.Any– Configuration for stepstepinconfigwith a step config ID equal tostep_config_id- Raises:
ValueError – No step could be found with ID equal to
step_config_idAttributeError –
configdoes not have a an attribute equal to the value given instep
load_hydrate_write_config_bundle#
- load_hydrate_write_config_bundle(configuration_file, load_configuration_file, create_config_bundle, root_dir_output_run, converter)[source]#
Load, hydrate and write (to disk)
ConfigBundleLike- Parameters:
configuration_file (
pathlib.Path) – File from which to load the configurationload_configuration_file (
typing.Callable[[pathlib.Path],typing.TypeVar(AI, bound=attr.AttrsInstance)]) – Callable to use to load the configuration from a filecreate_config_bundle (
pydoit_nb.typing.ConfigBundleCreator[typing.TypeVar(AI, bound=attr.AttrsInstance),typing.TypeVar(CB, bound=pydoit_nb.typing.ConfigBundleLike[typing.Any])]) – Callable to use to create theConfigBundleLikefrom the loaded configuration, the path in which the hydrated config will be written and the run’s output root directory.root_dir_output_run (
pathlib.Path) – Root directory in which to write output for this runconverter (
pydoit_nb.typing.Converter) – Converter to use to serialise the outputConfigBundleLiketo disk
- Returns:
typing.TypeVar(CB, bound=pydoit_nb.typing.ConfigBundleLike[typing.Any]) – LoadedConfigBundleLike