44from pathlib import Path
55
66
7+
78def clean_dict (obj ):
89 """Remove keys from the dictionary where the corresponding value is None.
910
@@ -24,8 +25,10 @@ def clean_dict(obj):
2425 return obj
2526
2627
27- def stringify (obj ):
28- """Convert None to an empty string.
28+ def _stringify (obj ):
29+ """
30+ Convert None to an empty string.
31+
2932
3033 Parameters
3134 ----------
@@ -40,8 +43,10 @@ def stringify(obj):
4043 return obj if obj is not None else ""
4144
4245
43- def load_config (file_path ):
44- """Load configuration from a .json file.
46+ def _load_config (file_path ):
47+ """
48+ Load configuration from a .json file.
49+ >>>>>>> de55560eb525ef412c38bb31d21d43d9b170d3f6
4550
4651 Parameters
4752 ----------
@@ -62,29 +67,6 @@ def load_config(file_path):
6267 return {}
6368
6469
65- def _sorted_merge (* dicts ):
66- merged = {}
67- for d in dicts :
68- merged .update (d )
69- return merged
70-
71-
72- def _create_global_config (args ):
73- username = input (
74- f"Please enter the name you would want future work to be credited to " f"[{ args .get ('username' , '' )} ]: "
75- ).strip () or args .get ("username" , "" )
76- email = input (f"Please enter the your email " f"[{ args .get ('email' , '' )} ]: " ).strip () or args .get ("email" , "" )
77- return_bool = False if username is None or email is None else True
78- with open (Path ().home () / "diffpyconfig.json" , "w" ) as f :
79- f .write (json .dumps ({"username" : stringify (username ), "email" : stringify (email )}))
80- print (
81- f"You can manually edit the config file at { Path ().home () / 'diffpyconfig.json' } using any text editor.\n "
82- f"Or you can update the config file by passing new values to get_user_info(), "
83- f"see examples here: https://www.diffpy.org/diffpy.utils/examples/toolsexample.html"
84- )
85- return return_bool
86-
87-
8870def get_user_info (owner_name = None , owner_email = None , owner_orcid = None ):
8971 """Get name, email and orcid of the owner/user from various sources and
9072 return it as a metadata dictionary.
@@ -111,7 +93,7 @@ def get_user_info(owner_name=None, owner_email=None, owner_orcid=None):
11193 The name of the user who will show as owner in the metadata that is stored with the data
11294 owner_email: string, optional, default is the value stored in the global or local config file.
11395 The email of the user/owner
114- owner_name : string, optional, default is the value stored in the global or local config file.
96+ owner_orcid : string, optional, default is the value stored in the global or local config file.
11597 The ORCID id of the user/owner
11698
11799 Returns
@@ -124,8 +106,8 @@ def get_user_info(owner_name=None, owner_email=None, owner_orcid=None):
124106 for key , value in copy (runtime_info ).items ():
125107 if value is None or value == "" :
126108 del runtime_info [key ]
127- global_config = load_config (Path ().home () / "diffpyconfig.json" )
128- local_config = load_config (Path ().cwd () / "diffpyconfig.json" )
109+ global_config = _load_config (Path ().home () / "diffpyconfig.json" )
110+ local_config = _load_config (Path ().cwd () / "diffpyconfig.json" )
129111 # if global_config is None and local_config is None:
130112 # print(
131113 # "No global configuration file was found containing "
0 commit comments