sda.misc.config#
Functions to parse the ~/sda.json :ref:`Configuration file <label_config_file>.
Create a ~/sda.json file in your HOME that contains all machine-specific information
(e.g: path to data folders).
See DBFORMAT for expected format.
Attributes#
Functions#
|
Validate and normalize a path string using pathlib, preserving literal backslashes. |
|
Recursively update dict1 with dict2. |
|
Read the default SDA config.json file config_path. |
|
Create configuration with only test data paths to avoid SharePoint validation errors. |
|
Append test data paths to config for CI testing. |
|
Get configuration with test data paths appended. |
|
Create a sda.json file in the user's home directory if it does not exist. |
|
Read configuration file and returns it. |
Module Contents#
- sda.misc.config.CONFIG_PATH_DEFAULT#
- sda.misc.config.CONFIG_PATH_JSON#
- sda.misc.config.CONFIG_DATA_SHAREPOINTS_KEY = 'DATA_SHAREPOINTS'#
- sda.misc.config.validate_and_normalize_path(path_str, context='')#
Validate and normalize a path string using pathlib, preserving literal backslashes.
- sda.misc.config.deep_update(dict1, dict2)#
Recursively update dict1 with dict2.
This function merges two dictionaries, where dict2 overrides dict1. If both dictionaries have a key with a dictionary value, it merges them recursively. If the value in dict2 is not a dictionary, it simply replaces the value in dict1.
- sda.misc.config.get_config(config_path=CONFIG_PATH_JSON)#
Read the default SDA config.json file config_path.
Original code taken from RADIS (radis/radis#328)
When SDA_USE_TEST_DATA environment variable is set to “true”, automatically appends test data paths to the configuration for CI/testing environments.
- Parameters:
config_path (
Path, optional) – Path to configuration file. Override default file with the entries of the user config filen in CONFIG_PATH_DEFAULT. By default CONFIG_PATH_JSON.- Returns:
Configuration, with test data paths automatically included if SDA_USE_TEST_DATA=true
- Return type:
- Raises:
JSONDecodeError – If there is an error reading the JSON file (e.g. syntax error).
:raises .. minigallery:`: :py:class:`sda.misc.config.get_config:
- sda.misc.config.get_test_data_only_config(config, test_data_root=None)#
Create configuration with only test data paths to avoid SharePoint validation errors.
This function replaces all SharePoint paths with only test data paths, preventing validation errors when SharePoint paths don’t exist in CI environments.
- Parameters:
config (
dict) – Configuration dictionary to modifytest_data_root (
Path, optional) – Root path for test data. If None, uses tests/data relative to project root.
- Returns:
Modified configuration with only test data paths
- Return type:
Examples
>>> config = get_config() # Contains SharePoint paths >>> ci_config = get_ci_only_config(config) # Only test data paths
- sda.misc.config.append_test_data_to_config(config, test_data_root=None)#
Append test data paths to config for CI testing.
This function adds test data sharepoints to the configuration dictionary to allow tests to run with local test fixtures instead of requiring real SharePoint data.
- Parameters:
config (
dict) – Configuration dictionary to modifytest_data_root (
Path, optional) – Root path for test data. If None, uses tests/data relative to project root.
- Returns:
Modified configuration with test data paths added
- Return type:
Examples
>>> config = get_config() >>> config = append_test_data_to_config(config) >>> # Now config contains test data paths for T097, T083, etc.
- sda.misc.config.get_config_with_test_data(config_path=CONFIG_PATH_JSON, test_data_root=None)#
Get configuration with test data paths appended.
This is a convenience function that combines get_config() and append_test_data_to_config() for easy use in tests.
- Parameters:
config_path (
Path, optional) – Path to configuration file, by default CONFIG_PATH_JSONtest_data_root (
Path, optional) – Root path for test data. If None, uses tests/data relative to project root.
- Returns:
Configuration with test data paths included
- Return type:
Examples
>>> config = get_config_with_test_data() >>> # Use in tests or CI environments
- sda.misc.config.init_config_json(config_path_json, verbose=1)#
Create a sda.json file in the user’s home directory if it does not exist.
- Parameters:
config_path_json (
Path) – Path to the configuration file.verbose (
int, optional) – Verbosity level. If verbose is greater than 1, print the path of the configuration file. By default, it is set to False (no output).
- Raises:
JSONDecodeError – If there is an error reading the JSON file (e.g. syntax error).
FileNotFoundError – If the file does not exist.
- sda.misc.config.get_user_config(config_path=CONFIG_PATH_JSON)#
Read configuration file and returns it.
- Parameters:
config_path (
Path, optional) – Configuration file, by default CONFIG_PATH_JSON- Returns:
Configuration
- Return type:
- Raises:
JSONDecodeError – If there is an error reading the JSON file (e.g. syntax error).
- sda.misc.config.configuration_dict#