44from pathlib import Path
55
66
7- def _stringify (obj ):
7+ def clean_dict (obj ):
8+ """Remove keys from the dictionary where the corresponding value is None.
9+
10+ Parameters
11+ ----------
12+ obj: dict
13+ The dictionary to clean. If None, initialize as an empty dictionary.
14+
15+ Returns
16+ -------
17+ dict:
18+ The cleaned dictionary with keys removed where the value is None.
819 """
9- Convert None to an empty string.
20+ obj = obj if obj is not None else {}
21+ for key , value in copy (obj ).items ():
22+ if not value :
23+ del obj [key ]
24+ return obj
25+
26+
27+ def _stringify (obj ):
28+ """Convert None to an empty string.
1029
1130 Parameters
1231 ----------
@@ -22,8 +41,7 @@ def _stringify(obj):
2241
2342
2443def _load_config (file_path ):
25- """
26- Load configuration from a .json file.
44+ """Load configuration from a .json file.
2745
2846 Parameters
2947 ----------
@@ -34,7 +52,6 @@ def _load_config(file_path):
3452 -------
3553 dict:
3654 The configuration dictionary or {} if the config file does not exist.
37-
3855 """
3956 config_file = Path (file_path ).resolve ()
4057 if config_file .is_file ():
@@ -46,8 +63,8 @@ def _load_config(file_path):
4663
4764
4865def get_user_info (owner_name = None , owner_email = None , owner_orcid = None ):
49- """
50- Get name, email and orcid of the owner/user from various sources and return it as a metadata dictionary
66+ """Get name, email and orcid of the owner/user from various sources and
67+ return it as a metadata dictionary.
5168
5269 The function looks for the information in json format configuration files with the name 'diffpyconfig.json'.
5370 These can be in the user's home directory and in the current working directory. The information in the
@@ -79,7 +96,6 @@ def get_user_info(owner_name=None, owner_email=None, owner_orcid=None):
7996 dict:
8097 The dictionary containing username, email and orcid of the user/owner, and any other information
8198 stored in the global or local config files.
82-
8399 """
84100 runtime_info = {"owner_name" : owner_name , "owner_email" : owner_email , "owner_orcid" : owner_orcid }
85101 for key , value in copy (runtime_info ).items ():
@@ -104,8 +120,7 @@ def get_user_info(owner_name=None, owner_email=None, owner_orcid=None):
104120
105121
106122def get_package_info (package_names , metadata = None ):
107- """
108- Fetches package version and updates it into (given) metadata.
123+ """Fetches package version and updates it into (given) metadata.
109124
110125 Package info stored in metadata as {'package_info': {'package_name': 'version_number'}}.
111126
@@ -119,7 +134,6 @@ def get_package_info(package_names, metadata=None):
119134 -------
120135 dict:
121136 The updated metadata dict with package info inserted.
122-
123137 """
124138 if metadata is None :
125139 metadata = {}
0 commit comments