4
4
from pathlib import Path
5
5
6
6
7
- def clean_dict (obj ):
8
- """
9
- Remove keys from the dictionary where the corresponding value is None.
10
-
11
- Parameters
12
- ----------
13
- obj: dict
14
- The dictionary to clean. If None, initialize as an empty dictionary.
15
-
16
- Returns
17
- -------
18
- dict:
19
- The cleaned dictionary with keys removed where the value is None.
20
-
21
- """
22
- obj = obj if obj is not None else {}
23
- for key , value in copy (obj ).items ():
24
- if not value :
25
- del obj [key ]
26
- return obj
27
-
28
-
29
- def stringify (obj ):
7
+ def _stringify (obj ):
30
8
"""
31
9
Convert None to an empty string.
32
10
@@ -43,7 +21,7 @@ def stringify(obj):
43
21
return obj if obj is not None else ""
44
22
45
23
46
- def load_config (file_path ):
24
+ def _load_config (file_path ):
47
25
"""
48
26
Load configuration from a .json file.
49
27
@@ -67,29 +45,6 @@ def load_config(file_path):
67
45
return {}
68
46
69
47
70
- def _sorted_merge (* dicts ):
71
- merged = {}
72
- for d in dicts :
73
- merged .update (d )
74
- return merged
75
-
76
-
77
- def _create_global_config (args ):
78
- username = input (
79
- f"Please enter the name you would want future work to be credited to " f"[{ args .get ('username' , '' )} ]: "
80
- ).strip () or args .get ("username" , "" )
81
- email = input (f"Please enter the your email " f"[{ args .get ('email' , '' )} ]: " ).strip () or args .get ("email" , "" )
82
- return_bool = False if username is None or email is None else True
83
- with open (Path ().home () / "diffpyconfig.json" , "w" ) as f :
84
- f .write (json .dumps ({"username" : stringify (username ), "email" : stringify (email )}))
85
- print (
86
- f"You can manually edit the config file at { Path ().home () / 'diffpyconfig.json' } using any text editor.\n "
87
- f"Or you can update the config file by passing new values to get_user_info(), "
88
- f"see examples here: https://www.diffpy.org/diffpy.utils/examples/toolsexample.html"
89
- )
90
- return return_bool
91
-
92
-
93
48
def get_user_info (owner_name = None , owner_email = None , owner_orcid = None ):
94
49
"""
95
50
Get name, email and orcid of the owner/user from various sources and return it as a metadata dictionary
@@ -116,7 +71,7 @@ def get_user_info(owner_name=None, owner_email=None, owner_orcid=None):
116
71
The name of the user who will show as owner in the metadata that is stored with the data
117
72
owner_email: string, optional, default is the value stored in the global or local config file.
118
73
The email of the user/owner
119
- owner_name : string, optional, default is the value stored in the global or local config file.
74
+ owner_orcid : string, optional, default is the value stored in the global or local config file.
120
75
The ORCID id of the user/owner
121
76
122
77
Returns
@@ -130,8 +85,8 @@ def get_user_info(owner_name=None, owner_email=None, owner_orcid=None):
130
85
for key , value in copy (runtime_info ).items ():
131
86
if value is None or value == "" :
132
87
del runtime_info [key ]
133
- global_config = load_config (Path ().home () / "diffpyconfig.json" )
134
- local_config = load_config (Path ().cwd () / "diffpyconfig.json" )
88
+ global_config = _load_config (Path ().home () / "diffpyconfig.json" )
89
+ local_config = _load_config (Path ().cwd () / "diffpyconfig.json" )
135
90
# if global_config is None and local_config is None:
136
91
# print(
137
92
# "No global configuration file was found containing "
0 commit comments