Skip to content

Commit e2e0ead

Browse files
authored
Merge pull request #71 from yucongalicechen/user2
add docs for tools
2 parents 0e61164 + 7c7cceb commit e2e0ead

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.. _Tools Example:
2+
3+
:tocdepth: 2
4+
5+
Tools Example
6+
#############
7+
8+
This example will demonstrate how diffpy.utils allows us to load and manage username and email information.
9+
Using the tools module, we can efficiently get them in terms of a dictionary.
10+
11+
1) We have the function ``get_user_info`` that neatly returns a dictionary containing the username and email.
12+
You can use this function without arguments. ::
13+
14+
from diffpy.utils.tools import get_user_info
15+
user_info = get_user_info()
16+
17+
This function will first attempt to load configuration files
18+
from both the current working directory and the home directory.
19+
If no configuration files exist, it prompts for user input and creates a configuration file in the home directory.
20+
It prioritizes prompted user inputs, then current working directory, and finally home directory.
21+
If no configuration files or inputs are found, this function creates a configuration in the home directory
22+
with empty values for username and email stored as a dictionary.
23+
24+
2) You can also override existing values by passing a dictionary to the function. ::
25+
26+
new_args = {"username": "new_username", "email": "[email protected]"}
27+
new_user_info = get_user_info(new_args)
28+
29+
Here, the function returns a dictionary containing the new arguments.
30+
If no configuration files exist, it prompts for inputs again. The arguments passed here also override input values.
31+
The updated arguments will not be saved in files.
32+
33+
You can update only the username or email individually, for example ::
34+
35+
new_username = {"username": new_username}
36+
new_user_info = get_user_info(new_username)
37+
38+
This updates username to "new_username" while fetching the email from inputs or the configuration files.
39+
Similarly, you can update only the email. ::
40+
41+
new_email = {"email": [email protected]}
42+
new_user_info = get_user_info(new_email)
43+
44+
This updates the email to "[email protected]" while fetching the username from inputs or the configuration files.
45+
46+
47+
By using this function, we ensure that user information is correctly loaded, merged, and saved.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.. _Tools Utility:
2+
3+
:tocdepth: 2
4+
5+
Tools Utility
6+
#############
7+
8+
The ``diffpy.utils.tools`` module contains tool functions for use with diffpy apps.
9+
One of these functions, ``get_user_info``, is designed for managing and tracking username and email information.
10+
This function helps storing this data in a ``diffpyconfig.json`` file.
11+
12+
Users can use the module to simplify the process of loading, merging, and saving information consistently and easily.
13+
Additionally, it saves the effort of re-entering information, and allows overriding current information by
14+
passing parameters.

0 commit comments

Comments
 (0)