io_utils¶
Utilites for reading and writing files and other I/O operations
- merge_utils.io_utils.expand_path(path: str, base_dir: str | None = None) str[source]¶
Expand environment variables and user home in a path. If the path is relative and a base directory is provided, make the path absolute using the base directory.
- Parameters:
path – Path to expand
base_dir – Base directory for relative paths
- Returns:
Expanded path
- merge_utils.io_utils.find_cfg(name: str) str[source]¶
Find the full path to a configuration file
- Parameters:
name – Name of the configuration file
- Returns:
Full path to the configuration file
- Raises:
FileNotFoundError – If the file does not exist
- merge_utils.io_utils.find_file(name: str, dirs: list[str] | None = None, recursive: bool = False) str[source]¶
Locate a file by name in a list of directories
- Parameters:
name – File name or path to locate
dirs – List of directories to search
recursive – Check sub-directories recursively
- Returns:
Full path to the located file
- Raises:
FileNotFoundError – If the file does not exist
- merge_utils.io_utils.find_runner(name: str) str[source]¶
Find the full path to a runner script
- Parameters:
name – Name of the runner script
- Returns:
Full path to the runner script
- Raises:
FileNotFoundError – If the file does not exist
- merge_utils.io_utils.get_inputs(filelists: list[str] | None = None) list[str][source]¶
Get a list of inputs from the the file lists and standard input
- Parameters:
filelists – full paths to files containing lists of entries
- Returns:
combined list of entries
- merge_utils.io_utils.log_dict(msg: str, items: dict, level=30) int[source]¶
Log a message for a dictionary of items with counts
- merge_utils.io_utils.log_list(msg: str, items: Iterable, level=30) int[source]¶
Log a message for a list of items
- merge_utils.io_utils.log_nonzero(msg: str, value: int, level=10) int[source]¶
Log a message if the value is non-zero
- merge_utils.io_utils.log_print(msg: str, level=20) None[source]¶
Print a message and save it to the log file
- merge_utils.io_utils.read_config_file(name: str | None = None) dict[source]¶
Read a configuration file in JSON, TOML, or YAML format
- Parameters:
name – Name of the configuration file
- Returns:
Dictionary containing the configuration settings
- Raises:
FileNotFoundError – If the file does not exist
ValueError – If the file type is not supported
- merge_utils.io_utils.set_log_level(level: int) None[source]¶
Override the logging level for the console