Skip to content

Commit ee412c1

Browse files
committed
deploy: 2f3b5f0
1 parent deaa294 commit ee412c1

File tree

6 files changed

+84
-37
lines changed

6 files changed

+84
-37
lines changed

_sources/examples/toolsexample.rst.txt

Lines changed: 26 additions & 14 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 username and email 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": "new@example.com"}
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)
@@ -43,5 +42,18 @@ Using the tools module, we can efficiently get them in terms of a dictionary.
4342

4443
This updates the email to "new@email.com" while fetching the username from inputs or the configuration files.
4544

45+
3) We also have the function ``get_package_info``, which inserts or updates package names and versions
46+
in the given metadata dictionary under the key "package_info".
47+
It stores the package information as {"package_info": {"package_name": "version_number"}}.
48+
This function can be used as follows. ::
49+
50+
from diffpy.utils.tools import get_user_info
51+
package_metadata = get_package_info("my_package")
52+
53+
You can also specify an existing dictionary to be updated with the information. ::
54+
55+
existing_dict = {"key": "value"}
56+
updated_dict = get_package_info("my_package", metadata=existing_dict))
4657

47-
By using this function, we ensure that user 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.

_sources/utilities/toolsutility.rst.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
Tools Utility
66
#############
77

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.
8+
The ``diffpy.utils.tools`` module provides tool functions for use with diffpy apps.
119

12-
Users can use the module to simplify the process of loading, merging, and saving information consistently and easily.
10+
1) ``get_uder_info``: This function is designed for managing and tracking username and email information.
11+
12+
Developers can use this function to simplify the process of loading, merging, and saving information consistently and easily.
1313
Additionally, it saves the effort of re-entering information, and allows overriding current information by
1414
passing parameters.
15+
16+
2) ``get_package_info``: This function loads package name and version information into a dictionary.
17+
It updates the package information under the key "package_info" in the format {"package_name": "version_number"},
18+
resulting in an entry in the passed metadata dictionary that looks like
19+
`{"package_info": {"package1": "version_number1", "package2": "version_number2"} if the function is called more than
20+
once.
21+
22+
Users can use these functions to track and manage versions of packages that can later be stored, for example, in an output
23+
file header.

examples/toolsexample.html

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878

7979
<section id="id1">
8080
<h1>Tools Example<a class="headerlink" href="#id1" title="Link to this heading"></a></h1>
81-
<p>This example will demonstrate how diffpy.utils allows us to load and manage username and email information.
81+
<p>This example will demonstrate how diffpy.utils allows us to conveniently load and manage user and package information.
8282
Using the tools module, we can efficiently get them in terms of a dictionary.</p>
8383
<ol class="arabic">
8484
<li><p>We have the function <code class="docutils literal notranslate"><span class="pre">get_user_info</span></code> that neatly returns a dictionary containing the username and email.
@@ -87,22 +87,22 @@ <h1>Tools Example<a class="headerlink" href="#id1" title="Link to this heading">
8787
<span class="n">user_info</span> <span class="o">=</span> <span class="n">get_user_info</span><span class="p">()</span>
8888
</pre></div>
8989
</div>
90-
<p>This function will first attempt to load configuration files
91-
from both the current working directory and the home directory.
92-
If no configuration files exist, it prompts for user input and creates a configuration file in the home directory.
93-
It prioritizes prompted user inputs, then current working directory, and finally home directory.
94-
If no configuration files or inputs are found, this function creates a configuration in the home directory
95-
with empty values for username and email stored as a dictionary.</p>
90+
<p>This function will first attempt to load the information from configuration files looking first in
91+
the current working directory and then in the user’s home directory.
92+
If no configuration files exist, it prompts for user input and creates a configuration file in the home directory
93+
so that the next time the program is run it will no longer have to prompt the user.
94+
It can be passed user information which overrides looking in config files, and so could be passed
95+
information that is entered through a gui or command line interface to override default information at runtime.
96+
It prioritizes prompted user inputs, then current working directory config file, and finally home directory config file.</p>
97+
<p>The function returns a dictionary containing the username and email information.</p>
9698
</li>
97-
<li><p>You can also override existing values by passing a dictionary to the function.</p>
99+
<li><p>You can also override existing values by passing a dictionary to the function with the keys <cite>“username”</cite> and <cite>“email”</cite></p>
98100
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">new_args</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;username&quot;</span><span class="p">:</span> <span class="s2">&quot;new_username&quot;</span><span class="p">,</span> <span class="s2">&quot;email&quot;</span><span class="p">:</span> <span class="s2">&quot;new@example.com&quot;</span><span class="p">}</span>
99101
<span class="n">new_user_info</span> <span class="o">=</span> <span class="n">get_user_info</span><span class="p">(</span><span class="n">new_args</span><span class="p">)</span>
100102
</pre></div>
101103
</div>
102-
<p>Here, the function returns a dictionary containing the new arguments.
103-
If no configuration files exist, it prompts for inputs again. The arguments passed here also override input values.
104-
The updated arguments will not be saved in files.</p>
105-
<p>You can update only the username or email individually, for example</p>
104+
</li>
105+
<li><p>You can update only the username or email individually, for example</p>
106106
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">new_username</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;username&quot;</span><span class="p">:</span> <span class="n">new_username</span><span class="p">}</span>
107107
<span class="n">new_user_info</span> <span class="o">=</span> <span class="n">get_user_info</span><span class="p">(</span><span class="n">new_username</span><span class="p">)</span>
108108
</pre></div>
@@ -116,7 +116,25 @@ <h1>Tools Example<a class="headerlink" href="#id1" title="Link to this heading">
116116
<p>This updates the email to “<a class="reference external" href="mailto:new&#37;&#52;&#48;email&#46;com">new<span>&#64;</span>email<span>&#46;</span>com</a>” while fetching the username from inputs or the configuration files.</p>
117117
</li>
118118
</ol>
119-
<p>By using this function, we ensure that user information is correctly loaded, merged, and saved.</p>
119+
<ol class="arabic" start="3">
120+
<li><p>We also have the function <code class="docutils literal notranslate"><span class="pre">get_package_info</span></code>, which inserts or updates package names and versions
121+
in the given metadata dictionary under the key “package_info”.
122+
It stores the package information as {“package_info”: {“package_name”: “version_number”}}.
123+
This function can be used as follows.</p>
124+
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">diffpy.utils.tools</span> <span class="kn">import</span> <span class="n">get_user_info</span>
125+
<span class="n">package_metadata</span> <span class="o">=</span> <span class="n">get_package_info</span><span class="p">(</span><span class="s2">&quot;my_package&quot;</span><span class="p">)</span>
126+
</pre></div>
127+
</div>
128+
<p>You can also specify an existing dictionary to be updated with the information.</p>
129+
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>existing_dict = {&quot;key&quot;: &quot;value&quot;}
130+
updated_dict = get_package_info(&quot;my_package&quot;, metadata=existing_dict))
131+
132+
note that `&quot;diffpy.utils&quot;` is automatically included in the package info since the `get_user_info` function is
133+
part of diffpy.utils.
134+
</pre></div>
135+
</div>
136+
</li>
137+
</ol>
120138
</section>
121139

122140

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ <h1>diffpy.utils documentation<a class="headerlink" href="#diffpy-utils-document
8383
<p>diffpy.utils - general purpose shared utilities for the diffpy libraries.</p>
8484
<div class="line-block">
8585
<div class="line">Software version 3.3.1.</div>
86-
<div class="line">Last updated June 06, 2024.</div>
86+
<div class="line">Last updated June 07, 2024.</div>
8787
</div>
8888
<p>The diffpy.utils package provides general functions for extracting data from variously formatted text files as well as
8989
some PDF-specific functionality. These include wx GUI utilities used by the PDFgui program and an interpolation function

0 commit comments

Comments
 (0)