From 7112fac0c7804badf4ad41733cabec0960f063ff Mon Sep 17 00:00:00 2001 From: Alison Wu Date: Tue, 5 Nov 2024 16:31:25 -0500 Subject: [PATCH 1/9] Add warning to missing global config file --- news/get-user-fix.rst | 23 +++++++++++++++++++++++ src/diffpy/utils/tools.py | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 news/get-user-fix.rst diff --git a/news/get-user-fix.rst b/news/get-user-fix.rst new file mode 100644 index 00000000..5b2fd3df --- /dev/null +++ b/news/get-user-fix.rst @@ -0,0 +1,23 @@ +**Added:** + +* Warning message for missing global config file + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/utils/tools.py b/src/diffpy/utils/tools.py index 1dfb8284..dc908a27 100644 --- a/src/diffpy/utils/tools.py +++ b/src/diffpy/utils/tools.py @@ -3,6 +3,7 @@ import os from copy import copy from pathlib import Path +import warnings def clean_dict(obj): @@ -114,6 +115,7 @@ def get_user_info(args=None): global_config = load_config(Path().home() / "diffpyconfig.json") local_config = load_config(Path().cwd() / "diffpyconfig.json") if global_config is None and local_config is None: + warnings.warn("No global config file, please follow prompts below. For more information, refer to www.diffpy.org/diffpy.utils/") config_bool = _create_global_config(args) global_config = load_config(Path().home() / "diffpyconfig.json") config = _sorted_merge(clean_dict(global_config), clean_dict(local_config), clean_dict(args)) From d24acb6305e6c9247618fc20b9633162b1096e79 Mon Sep 17 00:00:00 2001 From: Alison Wu Date: Tue, 5 Nov 2024 16:39:23 -0500 Subject: [PATCH 2/9] fix line too long --- src/diffpy/utils/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffpy/utils/tools.py b/src/diffpy/utils/tools.py index dc908a27..7574d093 100644 --- a/src/diffpy/utils/tools.py +++ b/src/diffpy/utils/tools.py @@ -115,7 +115,7 @@ def get_user_info(args=None): global_config = load_config(Path().home() / "diffpyconfig.json") local_config = load_config(Path().cwd() / "diffpyconfig.json") if global_config is None and local_config is None: - warnings.warn("No global config file, please follow prompts below. For more information, refer to www.diffpy.org/diffpy.utils/") + warnings.warn("No global config file, please follow prompts below.") config_bool = _create_global_config(args) global_config = load_config(Path().home() / "diffpyconfig.json") config = _sorted_merge(clean_dict(global_config), clean_dict(local_config), clean_dict(args)) From 0a59a0be30f1b5acb811dca376d88c18de97ae82 Mon Sep 17 00:00:00 2001 From: Alison Wu Date: Tue, 5 Nov 2024 17:03:12 -0500 Subject: [PATCH 3/9] better wording for capture user info --- news/capture-user.rst | 23 +++++++++++++++++++++++ src/diffpy/utils/tools.py | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 news/capture-user.rst diff --git a/news/capture-user.rst b/news/capture-user.rst new file mode 100644 index 00000000..b789d46e --- /dev/null +++ b/news/capture-user.rst @@ -0,0 +1,23 @@ +**Added:** + +* Better wording on the capture user info functionality + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/utils/tools.py b/src/diffpy/utils/tools.py index 7574d093..aab4a64f 100644 --- a/src/diffpy/utils/tools.py +++ b/src/diffpy/utils/tools.py @@ -115,7 +115,9 @@ def get_user_info(args=None): global_config = load_config(Path().home() / "diffpyconfig.json") local_config = load_config(Path().cwd() / "diffpyconfig.json") if global_config is None and local_config is None: - warnings.warn("No global config file, please follow prompts below.") + warnings.warn("No global config file, please follow prompts below. " + "The global config file is very important in crediting your work in the future. " + "For more information, please refer to www.diffpy.org/diffpy.utils/examples/toolsexample.html") config_bool = _create_global_config(args) global_config = load_config(Path().home() / "diffpyconfig.json") config = _sorted_merge(clean_dict(global_config), clean_dict(local_config), clean_dict(args)) From 2379a62ca863778361395c8779ff16a190b055fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 5 Nov 2024 22:05:56 +0000 Subject: [PATCH 4/9] [pre-commit.ci] auto fixes from pre-commit hooks --- src/diffpy/utils/tools.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/diffpy/utils/tools.py b/src/diffpy/utils/tools.py index aab4a64f..2f165f87 100644 --- a/src/diffpy/utils/tools.py +++ b/src/diffpy/utils/tools.py @@ -1,9 +1,9 @@ import importlib.metadata import json import os +import warnings from copy import copy from pathlib import Path -import warnings def clean_dict(obj): @@ -115,9 +115,11 @@ def get_user_info(args=None): global_config = load_config(Path().home() / "diffpyconfig.json") local_config = load_config(Path().cwd() / "diffpyconfig.json") if global_config is None and local_config is None: - warnings.warn("No global config file, please follow prompts below. " - "The global config file is very important in crediting your work in the future. " - "For more information, please refer to www.diffpy.org/diffpy.utils/examples/toolsexample.html") + warnings.warn( + "No global config file, please follow prompts below. " + "The global config file is very important in crediting your work in the future. " + "For more information, please refer to www.diffpy.org/diffpy.utils/examples/toolsexample.html" + ) config_bool = _create_global_config(args) global_config = load_config(Path().home() / "diffpyconfig.json") config = _sorted_merge(clean_dict(global_config), clean_dict(local_config), clean_dict(args)) From 4bb5ecf7b6362594de8f099fbef3cc651aed7980 Mon Sep 17 00:00:00 2001 From: Alison Wu Date: Wed, 6 Nov 2024 17:06:04 -0500 Subject: [PATCH 5/9] delete unnecessary get-user-fix.rst --- news/get-user-fix.rst | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 news/get-user-fix.rst diff --git a/news/get-user-fix.rst b/news/get-user-fix.rst deleted file mode 100644 index 5b2fd3df..00000000 --- a/news/get-user-fix.rst +++ /dev/null @@ -1,23 +0,0 @@ -**Added:** - -* Warning message for missing global config file - -**Changed:** - -* - -**Deprecated:** - -* - -**Removed:** - -* - -**Fixed:** - -* - -**Security:** - -* From 2732b498d33c5799cb4565a3aa2f99740f363537 Mon Sep 17 00:00:00 2001 From: Alison Wu Date: Wed, 6 Nov 2024 17:41:11 -0500 Subject: [PATCH 6/9] edited get user prompt --- src/diffpy/utils/tools.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/diffpy/utils/tools.py b/src/diffpy/utils/tools.py index 2f165f87..812e320b 100644 --- a/src/diffpy/utils/tools.py +++ b/src/diffpy/utils/tools.py @@ -1,7 +1,6 @@ import importlib.metadata import json import os -import warnings from copy import copy from pathlib import Path @@ -78,11 +77,11 @@ def _sorted_merge(*dicts): def _create_global_config(args): username = input( - f"Please enter the name of the user to put in the diffpy global config file " + f"Please enter the name of the user would want future work to be credited to " f"[{args.get('username', '')}]: " ).strip() or args.get("username", "") email = input( - f"Please enter the email of the user to put in the diffpy global config file " + f"Please enter the email of the user " f"[{args.get('email', '')}]: " ).strip() or args.get("email", "") return_bool = False if username is None or email is None else True @@ -115,9 +114,8 @@ def get_user_info(args=None): global_config = load_config(Path().home() / "diffpyconfig.json") local_config = load_config(Path().cwd() / "diffpyconfig.json") if global_config is None and local_config is None: - warnings.warn( + print( "No global config file, please follow prompts below. " - "The global config file is very important in crediting your work in the future. " "For more information, please refer to www.diffpy.org/diffpy.utils/examples/toolsexample.html" ) config_bool = _create_global_config(args) From e36726e83e3135f76507236bebf7b76f90f7db72 Mon Sep 17 00:00:00 2001 From: Alison Wu Date: Wed, 6 Nov 2024 18:33:26 -0500 Subject: [PATCH 7/9] edited message and prompt to capture user info --- src/diffpy/utils/tools.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/diffpy/utils/tools.py b/src/diffpy/utils/tools.py index 812e320b..1e804212 100644 --- a/src/diffpy/utils/tools.py +++ b/src/diffpy/utils/tools.py @@ -77,11 +77,11 @@ def _sorted_merge(*dicts): def _create_global_config(args): username = input( - f"Please enter the name of the user would want future work to be credited to " + f"Please enter the name you would want future work to be credited to " f"[{args.get('username', '')}]: " ).strip() or args.get("username", "") email = input( - f"Please enter the email of the user " + f"Please enter the your email " f"[{args.get('email', '')}]: " ).strip() or args.get("email", "") return_bool = False if username is None or email is None else True @@ -115,7 +115,11 @@ def get_user_info(args=None): local_config = load_config(Path().cwd() / "diffpyconfig.json") if global_config is None and local_config is None: print( - "No global config file, please follow prompts below. " + "No global configuration file was found containing information about the user to associate with the data. " + "By following the prompts below you can add your name and email to this file on the current computer and " + "your name will be automatically associated with subsequent diffpy data by default. " + "This is not recommended on a shared or public computer. " + "You will only have to do that once. " "For more information, please refer to www.diffpy.org/diffpy.utils/examples/toolsexample.html" ) config_bool = _create_global_config(args) From c367349d85bb39510d7987dba3abb47d660be10f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 6 Nov 2024 23:33:43 +0000 Subject: [PATCH 8/9] [pre-commit.ci] auto fixes from pre-commit hooks --- src/diffpy/utils/tools.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/diffpy/utils/tools.py b/src/diffpy/utils/tools.py index 1e804212..461d3f71 100644 --- a/src/diffpy/utils/tools.py +++ b/src/diffpy/utils/tools.py @@ -77,13 +77,9 @@ def _sorted_merge(*dicts): def _create_global_config(args): username = input( - f"Please enter the name you would want future work to be credited to " - f"[{args.get('username', '')}]: " + f"Please enter the name you would want future work to be credited to " f"[{args.get('username', '')}]: " ).strip() or args.get("username", "") - email = input( - f"Please enter the your email " - f"[{args.get('email', '')}]: " - ).strip() or args.get("email", "") + email = input(f"Please enter the your email " f"[{args.get('email', '')}]: ").strip() or args.get("email", "") return_bool = False if username is None or email is None else True with open(Path().home() / "diffpyconfig.json", "w") as f: f.write(json.dumps({"username": stringify(username), "email": stringify(email)})) From 5bfc9dd539e21dd9d8a892fd7192646ce4360f67 Mon Sep 17 00:00:00 2001 From: Alison Wu Date: Wed, 6 Nov 2024 18:49:44 -0500 Subject: [PATCH 9/9] fixed pre-commit issues --- src/diffpy/utils/tools.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/diffpy/utils/tools.py b/src/diffpy/utils/tools.py index 461d3f71..82cca8c9 100644 --- a/src/diffpy/utils/tools.py +++ b/src/diffpy/utils/tools.py @@ -111,11 +111,12 @@ def get_user_info(args=None): local_config = load_config(Path().cwd() / "diffpyconfig.json") if global_config is None and local_config is None: print( - "No global configuration file was found containing information about the user to associate with the data. " - "By following the prompts below you can add your name and email to this file on the current computer and " - "your name will be automatically associated with subsequent diffpy data by default. " + "No global configuration file was found containing " + "information about the user to associate with the data.\n" + "By following the prompts below you can add your name and email to this file on the current" + " computer and your name will be automatically associated with subsequent diffpy data by default.\n" "This is not recommended on a shared or public computer. " - "You will only have to do that once. " + "You will only have to do that once.\n" "For more information, please refer to www.diffpy.org/diffpy.utils/examples/toolsexample.html" ) config_bool = _create_global_config(args)