curobo.config_io module

File utilities for CuRobo.

copy_file_to_path(
source_file,
destination_path,
)

Copy file from source to destination.

Parameters:
  • source_file (str) – Path of source file.

  • destination_path (str) – Path of destination directory.

Returns:

Destination path of copied file.

Return type:

str

file_exists(path)

Check if file exists.

Parameters:

path (str) – Path of file.

Returns:

True if file exists, False otherwise.

Return type:

bool

get_filename(
file_path,
remove_extension=False,
)

Get file name from file path, removing extension if required.

Parameters:
  • file_path (str) – Path of file.

  • remove_extension (bool) – If True, remove file extension.

Returns:

File name.

Return type:

str

get_files_from_dir(
dir_path,
extension,
contains,
)

Get list of files from directory with specified extension and containing a string.

Parameters:
  • dir_path – Path of directory.

  • extension (List[str]) – List of file extensions to filter.

  • contains (str) – String to filter file names.

Returns:

List of file names. Does not include path.

Return type:

List[str]

get_path_of_dir(file_path)

Get path of directory containing the file.

Parameters:

file_path (str) – Path of file.

Returns:

Path of directory containing the file.

Return type:

str

is_file_xrdf(file_path)

Check if file is an XRDF file.

Parameters:

file_path (str) – Path of file.

Returns:

True if file is xrdf, False otherwise.

Return type:

bool

join_path(path1, path2)

Join two paths, considering OS specific path separators.

Parameters:
  • path1 (Union[str, Path]) – Path prefix.

  • path2 (Union[str, Path]) – Path suffix. If path2 is an absolute path, path1 is ignored.

Returns:

Joined path as per standard path joining semantics: - If path2 is absolute, return path2 (ignore path1) - If path2 is relative, join path1 and path2

Return type:

str

load_yaml(file_path)

Load yaml file and return as dictionary. If file_path is a dictionary, return as is.

Note

This function calls resolve_config internally. Consider using resolve_config directly for more flexibility with typed config objects.

Parameters:

file_path (Union[str, Dict]) – File path to yaml file or dictionary.

Returns:

Dictionary containing yaml file content.

Return type:

Dict

merge_dict_a_into_b(a, b)

Merge dictionary values in “a” into dictionary “b”. Overwrite values in “b” if key exists.

Parameters:
  • a (Dict[str, Any]) – New dictionary to merge.

  • b (Dict[str, Any]) – Base dictionary to merge into.

Return type:

Dict[str, Any]

Returns:

Merged dictionary.

resolve_config(config)

Resolve configuration from file path or return as-is.

If config is a string (file path), loads and returns the YAML content as a dict. Otherwise, returns config unchanged. This allows passing: - A file path (str) to load from YAML - A dict (already parsed config) - A typed config object (e.g., RobotCfg) that passes through unchanged

Parameters:

config (Union[str, TypeVar(ConfigT)]) – A path to a YAML file, a dict, or an already-constructed config object.

Return type:

Union[Dict, TypeVar(ConfigT)]

Returns:

If config is a string, loads and returns the YAML as a dict. Otherwise, returns config unchanged.

write_yaml(data, file_path)

Write dictionary to yaml file.

Parameters:
  • data (Dict) – Dictionary to write to yaml file.

  • file_path (str) – Path to write the yaml file.