foundry_dev_tools.utils.config module#

Utils functions for the configuration.

The config directories/files. The environment config. Function to merge dictionaries. And the function that checks if the kwargs for a __init__ are correct, currently used for the foundry_dev_tools.config.config.Config and the token providers foundry_dev_tools.config.token_provider.

foundry_dev_tools.utils.config.cfg_files(use_project_config=True)[source]#

Returns all the possible configuration file paths (cached).

Returns a dict with the paths as keys. Sets are not ordered in python but dicts are since 3.8.

The first one is the system-wide config.

Parameters:

use_project_config (bool)

Return type:

dict[Path, None]

foundry_dev_tools.utils.config.user_cfg_files()[source]#

Returns all possible user configuration files.

Returns a dict with the paths as keys. Sets are not ordered in python but dicts are since 3.8.

Return type:

dict[Path, None]

foundry_dev_tools.utils.config.site_cfg_file()[source]#

Returns the site_config_path from platformdirs.

Return type:

Path

foundry_dev_tools.utils.config.user_cache()[source]#

Returns the cached directory for the user (cached).

Return type:

Path

foundry_dev_tools.utils.config.merge_dicts(a, b)[source]#

Merges two nested dicts.

Parameters:
Return type:

dict

foundry_dev_tools.utils.config.path_from_path_or_str(path)[source]#

Returns the same variable if instance of Path otherwise create a Path.

Parameters:

path (Path | PathLike[str] | str)

Return type:

Path

foundry_dev_tools.utils.config.find_project_config_file(project_directory=None, use_git=False, check_caller_file=True)[source]#

Get the project config file in a git repo.

Parameters:
  • project_directory (Path | None) – the path to a (sub)directory of a git repo, otherwise checks caller filename directory and working directory

  • use_git (bool) – passed to :py:meth:git_toplevel_dir

  • check_caller_file (bool) – if the directory of the current executed python script should be checked

Returns:

Path to the project config or None if no file was found

Return type:

Path | None

foundry_dev_tools.utils.config.get_environment_variable_config()[source]#

Returns the FDT_* environment variables as a config dict.

Return type:

dict

foundry_dev_tools.utils.config.entry_point_fdt_token_provider()[source]#

Returns the token provider implementations registered via entry points.

Return type:

dict[str, type[TokenProvider]]

foundry_dev_tools.utils.config.entry_point_fdt_api_client()[source]#

Returns the API clients registered via entry points.

Return type:

dict[str, type[APIClient]]

foundry_dev_tools.utils.config.check_init(init_class, config_path, kwargs)[source]#

Checks if the supplied kwargs from the config dict are valid for the class to be instantiated.

If a kwargs is of the wrong type it will try to be cast to the correct type. If this fails a FoundryConfigError will be raised. If it succeeds it will still show a warning, that the value has been cast.

Parameters:
  • init_class (type) – The class that will be instantiated with kwargs

  • config_path (str) – For the warnings/errors to show which config setting is invalid config.path + “.” + invalid_kwarg_name

  • kwargs (dict[str, Any]) – the kwargs to check

Returns:

dict the kwargs that (were cast to) work for the instantiated class

Return type:

valid_kwargs