rail.projects.name_utils module

Utility code to help define standard paths for various data products

class rail.projects.name_utils.NameFactory(config=None, templates=None, interpolants=None)[source]

Bases: object

Class defining standard paths for various data products

Parameters:
  • config (dict | None)

  • templates (dict | None)

  • interpolants (dict | None)

config_template = {'CommonPaths': {'catalogs_dir': '{root}/catalogs', 'pipelines_dir': '{project_dir}/pipelines', 'project': '', 'project_dir': '{root}/projects/{project}', 'project_scratch_dir': '{scratch_root}/projects/{project}', 'root': '.', 'scratch_root': '.'}, 'PathTemplates': {'ceci_file_path': '{tag}_{stage}.{suffix}', 'ceci_output_dir': '{project_dir}/data/{selection}_{flavor}', 'pipeline_path': '{pipelines_dir}/{pipeline}_{flavor}.yaml'}}
get_common_paths()[source]
Return type:

dict

get_path_templates()[source]
Return type:

dict

get_resolved_common_paths()[source]
Return type:

dict

get_template(section_key, path_key)[source]

Return the template for a particular file type

Return type:

str

Parameters:
  • section_key (str) – Which part of the config to look in E.g., (CommonPaths, PathTemplates, Files)

  • path_key (str) – Key for the specific template

Returns:

Template for file of this type

Return type:

str

property interpolants: dict

Return the dict of interpolants that are used to resolve templates

resolve_common_path(path_key, **kwargs)[source]

Return a particular common path template

Return type:

str

Parameters:
  • path_key (str) – Key for the specific template

  • kwargs (Any)

Returns:

Resolved path

Return type:

str

resolve_from_config(config)[source]

Resolve all the templates in a dict

Return type:

dict

Parameters:

config (dict) – Dictionary containing templates to be resolved

Returns:

Dictionary with resolved versions of the templates

Return type:

dict

resolve_path(config, path_key, **kwargs)[source]

Resolve a particular template in a config dict

Return type:

str

Parameters:
  • config (dict) – Dictionary containing templates to be resolved

  • path_key (str) – Key for the specific template

  • kwargs (Any)

Returns:

Resolved version of the template

Return type:

str

resolve_path_template(path_key, **kwargs)[source]

Return a particular path templated

Return type:

str

Parameters:
  • path_key (str) – Key for the specific template

  • kwargs (Any)

Returns:

Resolved path

Return type:

str

resolve_template(section_key, path_key, **kwargs)[source]

Return the template for a particular file type

Return type:

str

Parameters:
  • section_key (str) – Which part of the config to look in E.g., (CommonPaths, PathTemplates, Files)

  • path_key (str) – Key for the specific template

  • kwargs (Any)

Returns:

Resolved path

Return type:

str

rail.projects.name_utils.format_template(template, **kwargs)[source]

Resolve a specific template

This is fault-tolerant and will not raise KeyError if some of the required interpolants are missing, but rather just leave them untouched

Return type:

str

Parameters:
  • template (str)

  • kwargs (Any)

rail.projects.name_utils.get_required_interpolants(template)[source]

Get the list of interpolants required to format a template string

Return type:

list[str]

Parameters:

template (str)

Notes

‘interpolants’ are strings that must be replaced in to format a string, e.g., in “{project_dir}/models” “{project_dir}” would an interpolant

rail.projects.name_utils.resolve_dict(source, interpolants)[source]

Recursively resolve a dictionary using interpolants

Return type:

dict

Parameters:
  • source (dict) – Dictionary of string templates

  • interpolants (dict) – Dictionary of strings used to resolve templates

Returns:

Dictionary of resolved templates

Return type:

dict

rail.projects.name_utils.update_include_dict(orig_dict, include_dict)[source]

Update a dict by updating (instead of replacing) sub-dicts

Return type:

None

Parameters:
  • orig_dict (dict[str, Any]) – Original dict

  • include_dict (dict[str, Any],) – Dict used to update the original