Skip to content

Commit 0cf7ff7

Browse files
committed
deploy: e2e0ead
1 parent 93a0796 commit 0cf7ff7

File tree

6 files changed

+329
-1
lines changed

6 files changed

+329
-1
lines changed
Lines changed: 47 additions & 0 deletions
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": "new@example.com"}
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": new@email.com}
42+
new_user_info = get_user_info(new_email)
43+
44+
This updates the email to "new@email.com" 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.
Lines changed: 14 additions & 0 deletions
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.

examples/toolsexample.html

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<!DOCTYPE html>
2+
<html class="writer-html5" lang="en" data-content_root="../">
3+
<head>
4+
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
5+
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Tools Example &mdash; diffpy.utils 3.3.1 documentation</title>
8+
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=fa44fd50" />
9+
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
10+
11+
12+
<!--[if lt IE 9]>
13+
<script src="../_static/js/html5shiv.min.js"></script>
14+
<![endif]-->
15+
16+
<script src="../_static/jquery.js?v=5d32c60e"></script>
17+
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
18+
<script src="../_static/documentation_options.js?v=6f23fdb8"></script>
19+
<script src="../_static/doctools.js?v=9a2dae69"></script>
20+
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
21+
<script src="../_static/js/theme.js"></script>
22+
<link rel="index" title="Index" href="../genindex.html" />
23+
<link rel="search" title="Search" href="../search.html" />
24+
</head>
25+
26+
<body class="wy-body-for-nav">
27+
<div class="wy-grid-for-nav">
28+
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
29+
<div class="wy-side-scroll">
30+
<div class="wy-side-nav-search" >
31+
32+
33+
34+
<a href="../index.html" class="icon icon-home">
35+
diffpy.utils
36+
</a>
37+
<div class="version">
38+
3.3.1
39+
</div>
40+
<div role="search">
41+
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
42+
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
43+
<input type="hidden" name="check_keywords" value="yes" />
44+
<input type="hidden" name="area" value="default" />
45+
</form>
46+
</div>
47+
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
48+
<ul>
49+
<li class="toctree-l1"><a class="reference internal" href="../license.html">License</a></li>
50+
<li class="toctree-l1"><a class="reference internal" href="../release.html">Release Notes</a></li>
51+
<li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
52+
<li class="toctree-l1"><a class="reference internal" href="../api/diffpy.utils.html">Package API</a></li>
53+
</ul>
54+
55+
</div>
56+
</div>
57+
</nav>
58+
59+
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
60+
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
61+
<a href="../index.html">diffpy.utils</a>
62+
</nav>
63+
64+
<div class="wy-nav-content">
65+
<div class="rst-content">
66+
<div role="navigation" aria-label="Page navigation">
67+
<ul class="wy-breadcrumbs">
68+
<li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
69+
<li class="breadcrumb-item active">Tools Example</li>
70+
<li class="wy-breadcrumbs-aside">
71+
<a href="../_sources/examples/toolsexample.rst.txt" rel="nofollow"> View page source</a>
72+
</li>
73+
</ul>
74+
<hr/>
75+
</div>
76+
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
77+
<div itemprop="articleBody">
78+
79+
<section id="id1">
80+
<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.
82+
Using the tools module, we can efficiently get them in terms of a dictionary.</p>
83+
<ol class="arabic">
84+
<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.
85+
You can use this function without arguments.</p>
86+
<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>
87+
<span class="n">user_info</span> <span class="o">=</span> <span class="n">get_user_info</span><span class="p">()</span>
88+
</pre></div>
89+
</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>
96+
</li>
97+
<li><p>You can also override existing values by passing a dictionary to the function.</p>
98+
<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>
99+
<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>
100+
</pre></div>
101+
</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>
106+
<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>
107+
<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>
108+
</pre></div>
109+
</div>
110+
<p>This updates username to “new_username” while fetching the email from inputs or the configuration files.
111+
Similarly, you can update only the email.</p>
112+
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">new_email</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;email&quot;</span><span class="p">:</span> <span class="n">new</span><span class="nd">@email</span><span class="o">.</span><span class="n">com</span><span class="p">}</span>
113+
<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_email</span><span class="p">)</span>
114+
</pre></div>
115+
</div>
116+
<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>
117+
</li>
118+
</ol>
119+
<p>By using this function, we ensure that user information is correctly loaded, merged, and saved.</p>
120+
</section>
121+
122+
123+
</div>
124+
</div>
125+
<footer>
126+
127+
<hr/>
128+
129+
<div role="contentinfo">
130+
<p>&#169; Copyright 2024, Brookhaven National Laboratory.</p>
131+
</div>
132+
133+
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
134+
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
135+
provided by <a href="https://readthedocs.org">Read the Docs</a>.
136+
137+
138+
</footer>
139+
</div>
140+
</div>
141+
</section>
142+
</div>
143+
<script>
144+
jQuery(function () {
145+
SphinxRtdTheme.Navigation.enable(true);
146+
});
147+
</script>
148+
149+
</body>
150+
</html>

objects.inv

57 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)