diffpy.utils package

Shared utilities for diffpy packages

Subpackages

Submodules

diffpy.utils.tools module

diffpy.utils.tools.clean_dict(obj)[source]

Remove keys from the dictionary where the corresponding value is None.

Parameters:

obj (dict) – The dictionary to clean. If None, initialize as an empty dictionary.

Returns:

The cleaned dictionary with keys removed where the value is None.

Return type:

dict

diffpy.utils.tools.get_package_info(package_names, metadata=None)[source]

Fetches package version and updates it into (given) metadata.

Package info stored in metadata as {‘package_info’: {‘package_name’: ‘version_number’}}.

metadatadict

The dictionary to store the package info. If not provided, a new dictionary will be created.

Returns:

The updated metadata dict with package info inserted.

Return type:

dict

diffpy.utils.tools.get_user_info(args=None)[source]

Get username and email configuration.

First attempts to load config file from global and local paths. If neither exists, creates a global config file. It prioritizes values from args, then local, then global. Removes invalid global config file if creation is needed, replacing it with empty username and email.

Parameters:

argparse.Namespace (args) – The arguments from the parser, default is None.

Returns:

The dictionary containing username and email with corresponding values.

Return type:

dict or None

diffpy.utils.tools.load_config(file_path)[source]

Load configuration from a .json file.

Parameters:

file_path (Path) – The path to the configuration file.

Returns:

The configuration dictionary or None if file does not exist.

Return type:

dict

diffpy.utils.tools.stringify(obj)[source]

Convert None to an empty string.

Parameters:

obj (str) – The object to convert. If None, return an empty string.

Returns:

The converted string if obj is not None, otherwise an empty string.

Return type:

str or None