@@ -85,7 +85,16 @@ def _sorted_merge(*dicts):
8585 return merged
8686
8787
88+ def _get_config_info (user_info ):
89+ global_config = _load_config (Path ().home () / "diffpyconfig.json" )
90+ local_config = _load_config (Path ().cwd () / "diffpyconfig.json" )
91+ if global_config or local_config :
92+ return _sorted_merge (global_config , local_config , user_info )
93+ return None
94+
95+
8896def _create_global_config (user_info ):
97+ print (user_info_imsg )
8998 username = input (
9099 f"Please enter the name you would want future work to be credited to "
91100 f"[{ user_info .get ('username' , '' )} ]: "
@@ -108,14 +117,13 @@ def _create_global_config(user_info):
108117
109118def get_user_info (user_info = None , skip_config_creation = False ):
110119 """
111- Get username and email configuration .
120+ Retrieve or create user configuration ( username and email) .
112121
113122 Workflow:
114- 1. First attempts to load config file from global and local paths.
115- 2. If config files exist, prioritizes values from user_info, then local config, then global config.
116- 3. Otherwise, if user wants to skip config creation, uses user_info as the final config, even if it's empty.
117- 4. Otherwise, if no config files exist and user does not want to skip config creation, prompts for user inputs.
118- 5. If no config files exist, a global config file will only be created if both username and email are valid.
123+ 1. Loads config from global and local paths, prioritizing user_info, then local, then global.
124+ 2. If no config files are found and skip_config_creation is False, prompts the user for input.
125+ Creates a global config file only if both username and email are valid.
126+ 3. If no config files and skip_config_creation is True, uses user_info (even if empty).
119127
120128 Parameters
121129 ----------
@@ -127,17 +135,15 @@ def get_user_info(user_info=None, skip_config_creation=False):
127135 dict or None:
128136 The dictionary containing username and email with corresponding values.
129137 """
130- global_config = _load_config (Path ().home () / "diffpyconfig.json" )
131- local_config = _load_config (Path ().cwd () / "diffpyconfig.json" )
132- if global_config or local_config :
133- return _sorted_merge (global_config , local_config , user_info )
134- if skip_config_creation :
135- return {
136- "username" : _stringify (user_info .get ("username" , "" )),
137- "email" : _stringify (user_info .get ("email" , "" )),
138- }
139- print (user_info_imsg )
140- return _create_global_config (user_info )
138+ config = _get_config_info (user_info )
139+ if config :
140+ return config
141+ if not skip_config_creation :
142+ return _create_global_config (user_info )
143+ return {
144+ "username" : _stringify (user_info .get ("username" , "" )),
145+ "email" : _stringify (user_info .get ("email" , "" )),
146+ }
141147
142148
143149def get_package_info (package_names , metadata = None ):
0 commit comments