@@ -75,11 +75,14 @@ def _sorted_merge(*dicts):
7575 return merged
7676
7777
78- def _create_global_config (args ):
78+ def _create_global_config (user_info ):
7979 username = input (
80- f"Please enter the name you would want future work to be credited to " f"[{ args .get ('username' , '' )} ]: "
81- ).strip () or args .get ("username" , "" )
82- email = input (f"Please enter the your email " f"[{ args .get ('email' , '' )} ]: " ).strip () or args .get ("email" , "" )
80+ f"Please enter the name you would want future work to be credited to "
81+ f"[{ user_info .get ('username' , '' )} ]: "
82+ ).strip () or user_info .get ("username" , "" )
83+ email = input (f"Please enter the your email " f"[{ user_info .get ('email' , '' )} ]: " ).strip () or user_info .get (
84+ "email" , ""
85+ )
8386 return_bool = False if username is None or email is None else True
8487 with open (Path ().home () / "diffpyconfig.json" , "w" ) as f :
8588 f .write (json .dumps ({"username" : stringify (username ), "email" : stringify (email )}))
@@ -91,19 +94,19 @@ def _create_global_config(args):
9194 return return_bool
9295
9396
94- def get_user_info (args = None ):
97+ def get_user_info (user_info = None ):
9598 """
9699 Get username and email configuration.
97100
98101 First attempts to load config file from global and local paths.
99102 If neither exists, creates a global config file.
100- It prioritizes values from args , then local, then global.
103+ It prioritizes values from user_info , then local, then global.
101104 Removes invalid global config file if creation is needed, replacing it with empty username and email.
102105
103106 Parameters
104107 ----------
105- args argparse.Namespace
106- The arguments from the parser , default is None.
108+ user_info dict or None
109+ A dictionary containing the user input , default is None.
107110
108111 Returns
109112 -------
@@ -124,9 +127,9 @@ def get_user_info(args=None):
124127 "You will only have to do that once.\n "
125128 "For more information, please refer to www.diffpy.org/diffpy.utils/examples/toolsexample.html"
126129 )
127- config_bool = _create_global_config (args )
130+ config_bool = _create_global_config (user_info )
128131 global_config = load_config (Path ().home () / "diffpyconfig.json" )
129- config = _sorted_merge (clean_dict (global_config ), clean_dict (local_config ), clean_dict (args ))
132+ config = _sorted_merge (clean_dict (global_config ), clean_dict (local_config ), clean_dict (user_info ))
130133 if config_bool is False :
131134 os .remove (Path ().home () / "diffpyconfig.json" )
132135 config = {"username" : "" , "email" : "" }
0 commit comments