Skip to content

Commit 10f110b

Browse files
authored
more tweaks by simon
1 parent 00e283c commit 10f110b

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

doc/manual/source/examples/toolsexample.rst

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Tools Example
66
#############
77

8-
This example will demonstrate how diffpy.utils allows us to load and manage user and package information.
8+
This example will demonstrate how diffpy.utils allows us to conveniently load and manage user and package information.
99
Using the tools module, we can efficiently get them in terms of a dictionary.
1010

1111
1) We have the function ``get_user_info`` that neatly returns a dictionary containing the username and email.
@@ -14,23 +14,22 @@ Using the tools module, we can efficiently get them in terms of a dictionary.
1414
from diffpy.utils.tools import get_user_info
1515
user_info = get_user_info()
1616

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.
17+
This function will first attempt to load the information from configuration files looking first in
18+
the current working directory and then in the user's home directory.
19+
If no configuration files exist, it prompts for user input and creates a configuration file in the home directory
20+
so that the next time the program is run it will no longer have to prompt the user.
21+
It can be passed user information which overrides looking in config files, and so could be passed
22+
information that is entered through a gui or command line interface to override default information at runtime.
23+
It prioritizes prompted user inputs, then current working directory config file, and finally home directory config file.
2324

24-
2) You can also override existing values by passing a dictionary to the function. ::
25+
The function returns a dictionary containing the username and email information.
26+
27+
2) You can also override existing values by passing a dictionary to the function with the keys `"username"` and `"email"` ::
2528

2629
new_args = {"username": "new_username", "email": "[email protected]"}
2730
new_user_info = get_user_info(new_args)
2831

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 ::
32+
3) You can update only the username or email individually, for example ::
3433

3534
new_username = {"username": new_username}
3635
new_user_info = get_user_info(new_username)
@@ -49,26 +48,12 @@ Using the tools module, we can efficiently get them in terms of a dictionary.
4948
This function can be used as follows. ::
5049

5150
from diffpy.utils.tools import get_user_info
52-
package_metadata = get_package_info("diffpy.utils")
51+
package_metadata = get_package_info("my_package")
5352

54-
You can also specify a specific metadata dictionary to store the information. ::
53+
You can also specify an existing dictionary to be updated with the information. ::
5554

5655
existing_dict = {"key": "value"}
57-
existing_dict.update(get_package_info("diffpy.utils", metadata=existing_dict))
58-
59-
In this case, the function inserts the package info into ``existing_dict``.
60-
61-
If you want to specify package other than "diffpy.utils",
62-
"diffpy.utils" is automatically included in the package info. ::
63-
64-
existing_dict.update(get_package_info("new_package", metadata=existing_dict))
65-
66-
The package info will then contain information for both "diffpy.utils" and "new_package".
67-
68-
4) We can also use ``get_package_info`` with diffraction objects to update the package information. ::
69-
70-
from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object
71-
example = Diffraction_object()
72-
example.metadata.update(get_package_info("diffpy.utils", metadata=example.metadata))
56+
updated_dict = get_package_info("my_package", metadata=existing_dict))
7357

74-
By using this module, we ensure that user and package information is correctly loaded, merged, and saved.
58+
note that `"diffpy.utils"` is automatically included in the package info since the `get_user_info` function is
59+
part of diffpy.utils.

0 commit comments

Comments
 (0)