Skip to content

Commit bb2a3e3

Browse files
committed
Resolve conflict for tools.py
2 parents 660f8a1 + de55560 commit bb2a3e3

File tree

9 files changed

+257
-111
lines changed

9 files changed

+257
-111
lines changed

doc/source/examples/tools_example.rst

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The function will return
4141

4242
.. code-block:: python
4343
44-
{"owner_email": "janedoe@email.com", "owner_name": "Jane Doe", "owner_orcid": "0000-0000-0000-0000"}
44+
{"owner_name": "Jane Doe", "owner_email": "janedoe@email.com", "owner_orcid": "0000-0000-0000-0000"}
4545
4646
4747
Where does ``get_user_info()`` get the user information from?
@@ -77,6 +77,7 @@ When building an application where you want to capture data-owner information, w
7777
``check_and_build_global_config()`` first followed by ``get_user_info`` in your app workflow. E.g.,
7878

7979
.. code-block:: python
80+
8081
from diffpy.utils.tools import check_and_build_global_config, get_user_info
8182
from datetime import datetime
8283
import json
@@ -95,12 +96,30 @@ it will only run once. However, if you want to bypass this behavior,
9596
``check_and_build_global_config()`` takes an optional boolean ``skip_config_creation`` parameter that
9697
could be set to ``True`` at runtime to override the config creation.
9798

99+
What happens when you run ``check_and_build_global_config()``?
100+
--------------------------------------------------------------
101+
102+
When you set ``skip_config_creation`` to ``False`` and there is no existing global configuration file,
103+
the function will prompt you for inputs (name, email, ORCID).
104+
An example of the prompts you may see is:
105+
106+
.. code-block:: python
107+
108+
Please enter the name you would want future work to be credited to: Jane Doe
109+
Please enter your email: janedoe@example.com
110+
Please enter your orcid ID if you know it: 0000-0000-0000-0000
111+
112+
113+
After receiving the inputs, the function will write the information to
114+
the `diffpyconfig.json` file in your home directory.
115+
116+
98117
I entered the wrong information in my config file so it always loads incorrect information, how do I fix that?
99118
--------------------------------------------------------------------------------------------------------------
100119

101120
It is easy to fix this simply by deleting the global and/or local config files, which will allow
102121
you to re-enter the information during the ``check_and_build_global_config()`` initialization
103-
workflow. You can also simply editi the ``diffpyconfig.json`` file directly using a text
122+
workflow. You can also simply edit the ``diffpyconfig.json`` file directly using a text
104123
editor.
105124

106125
Locate the file ``diffpyconfig.json``, in your home directory and open it in an editor ::
@@ -111,7 +130,7 @@ Locate the file ``diffpyconfig.json``, in your home directory and open it in an
111130
"owner_orcid": "0000-0000-4321-1234"
112131
}
113132

114-
Then you can edit the username and email as needed, make sure to save your edits.
133+
Then you can edit the username and email as needed, make sure to save your edits.
115134

116135
Automatically Capture Info about a Software Package Being Used
117136
==============================================================

doc/source/utilities/tools_utility.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ Tools Utility
55

66
The ``diffpy.utils.tools`` module provides tool functions for use with diffpy apps.
77

8-
- ``get_user_info()``: This function is designed for managing and tracking username and email information.
9-
8+
- ``get_user_info()``: This function is designed for managing and tracking user information (name, email, orcid).
109
Developers can use this function to simplify the process of loading, merging, and saving information consistently and easily.
1110
Additionally, it saves the effort of re-entering information, and allows overriding current information by
1211
passing parameters.
1312

13+
- ``check_and_build_global_config()``: This function helps create a global configuration file
14+
that can be used by, for example, ``get_user_info()``.
15+
If no existing configuration file is found, this function prompts for information.
16+
The provided inputs are then saved to a global configuration file.
17+
This file can be reused later by ``get_user_info()`` to ensure that the work credits and user information are consistently stored.
18+
1419
- ``get_package_info()``: This function loads package name and version information into a dictionary.
1520
It updates the package information under the key "package_info" in the format {"package_name": "version_number"},
1621
resulting in an entry in the passed metadata dictionary that looks like

news/pytest-comment.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Group's Pytest practices for using @pytest.mark.parametrize in test_diffraction_objects.py
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

news/pytest-reformat-transform.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news added: previous PR already contains has an news item for refactoring test_transform.py
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

news/test-func-format-compact.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* test comment format with compact style without extra line for each comment
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

news/user_info_doc.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* no news added: simply adding documentation for config update workflow
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/utils/tools.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55

66

7+
78
def 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-
8870
def 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

Comments
 (0)