Skip to content

Commit

Permalink
Deploying to gh-pages from @ 1f37dee 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmor-ms committed Oct 9, 2024
1 parent a06928e commit 502ab69
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 3 deletions.
72 changes: 72 additions & 0 deletions essex-config/annotations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,24 @@
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#parser" class="md-nav__link">
<span class="md-ellipsis">
Parser
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#updatable" class="md-nav__link">
<span class="md-ellipsis">
Updatable
</span>
</a>

</li>

</ul>
Expand Down Expand Up @@ -563,6 +581,24 @@
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#parser" class="md-nav__link">
<span class="md-ellipsis">
Parser
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#updatable" class="md-nav__link">
<span class="md-ellipsis">
Updatable
</span>
</a>

</li>

</ul>
Expand Down Expand Up @@ -621,6 +657,42 @@ <h2 id="alias">Alias</h2>
<a id="__codelineno-2-5" name="__codelineno-2-5" href="#__codelineno-2-5"></a> <span class="n">password</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="n">Field</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">&quot;DB connection password&quot;</span><span class="p">)</span>
</code></pre></div>
<p><code>essex-config</code> will look to populate <code>host</code> from <code>customer_db_host</code> when using the <code>EnvSource</code>.</p>
<h2 id="parser">Parser</h2>
<p>You can use custom parsers to handle specific data formats. For example:</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="k">class</span> <span class="nc">CustomParserConfig</span><span class="p">(</span><span class="n">BaseModel</span><span class="p">):</span>
<a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a> <span class="n">custom_parser</span><span class="p">:</span> <span class="n">Annotated</span><span class="p">[</span><span class="nb">list</span><span class="p">[</span><span class="nb">int</span><span class="p">],</span> <span class="n">Parser</span><span class="p">(</span><span class="n">json_list_parser</span><span class="p">)]</span>
<a id="__codelineno-3-3" name="__codelineno-3-3" href="#__codelineno-3-3"></a>
<a id="__codelineno-3-4" name="__codelineno-3-4" href="#__codelineno-3-4"></a><span class="n">config</span> <span class="o">=</span> <span class="n">load_config</span><span class="p">(</span><span class="n">CustomParserConfig</span><span class="p">)</span>
<a id="__codelineno-3-5" name="__codelineno-3-5" href="#__codelineno-3-5"></a><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">custom_parser</span><span class="p">)</span>
</code></pre></div>
<p>Essex-config offers <code>json_list_parser</code> and <code>plain_text_list_parser</code> by default from <code>essex_config.sources.utils</code>. You can also create your own parsers by providing a function that takes a string and a type as arguments and returns an instance of that type.</p>
<h2 id="updatable">Updatable</h2>
<p>The Updatable annotation indicates that the variable can be updated by other sources. For example:</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="k">class</span> <span class="nc">UpdatableConfig</span><span class="p">(</span><span class="n">BaseModel</span><span class="p">):</span>
<a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a> <span class="n">value</span><span class="p">:</span> <span class="n">Annotated</span><span class="p">[</span><span class="nb">dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">],</span> <span class="n">Updatable</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="p">{</span><span class="o">**</span><span class="n">x</span><span class="p">,</span> <span class="o">**</span><span class="n">y</span><span class="p">})]</span>
<a id="__codelineno-4-3" name="__codelineno-4-3" href="#__codelineno-4-3"></a>
<a id="__codelineno-4-4" name="__codelineno-4-4" href="#__codelineno-4-4"></a><span class="n">config</span> <span class="o">=</span> <span class="n">load_config</span><span class="p">(</span>
<a id="__codelineno-4-5" name="__codelineno-4-5" href="#__codelineno-4-5"></a> <span class="n">UpdatableConfig</span><span class="p">,</span>
<a id="__codelineno-4-6" name="__codelineno-4-6" href="#__codelineno-4-6"></a> <span class="n">sources</span><span class="o">=</span><span class="p">[</span>
<a id="__codelineno-4-7" name="__codelineno-4-7" href="#__codelineno-4-7"></a> <span class="n">ArgSource</span><span class="p">(</span><span class="n">value</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;a&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">}),</span>
<a id="__codelineno-4-8" name="__codelineno-4-8" href="#__codelineno-4-8"></a> <span class="n">ArgSource</span><span class="p">(</span><span class="n">value</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;b&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">}),</span>
<a id="__codelineno-4-9" name="__codelineno-4-9" href="#__codelineno-4-9"></a> <span class="n">ArgSource</span><span class="p">(</span><span class="n">value</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;a&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">}),</span>
<a id="__codelineno-4-10" name="__codelineno-4-10" href="#__codelineno-4-10"></a> <span class="p">],</span>
<a id="__codelineno-4-11" name="__codelineno-4-11" href="#__codelineno-4-11"></a><span class="p">)</span>
<a id="__codelineno-4-12" name="__codelineno-4-12" href="#__codelineno-4-12"></a><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
</code></pre></div>
<p>In this case, Updatable gets a function that defines how to update the variable and the <code>config.value</code> will contain:</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="p">{</span>
<a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a> <span class="s2">&quot;a&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
<a id="__codelineno-5-3" name="__codelineno-5-3" href="#__codelineno-5-3"></a> <span class="s2">&quot;b&quot;</span><span class="p">:</span> <span class="mi">2</span>
<a id="__codelineno-5-4" name="__codelineno-5-4" href="#__codelineno-5-4"></a><span class="p">}</span>
</code></pre></div>
<p>Without the Updatable annotation the values would be:</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="p">{</span>
<a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a> <span class="s2">&quot;a&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a> <span class="s2">&quot;b&quot;</span><span class="p">:</span> <span class="mi">2</span>
<a id="__codelineno-6-4" name="__codelineno-6-4" href="#__codelineno-6-4"></a><span class="p">}</span>
</code></pre></div>



Expand Down
78 changes: 78 additions & 0 deletions essex-config/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,39 @@
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#string-interpolation" class="md-nav__link">
<span class="md-ellipsis">
String Interpolation
</span>
</a>

<nav class="md-nav" aria-label="String Interpolation">
<ul class="md-nav__list">

<li class="md-nav__item">
<a href="#environment-variables" class="md-nav__link">
<span class="md-ellipsis">
Environment Variables
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#self-configuration-reference" class="md-nav__link">
<span class="md-ellipsis">
Self Configuration Reference
</span>
</a>

</li>

</ul>
</nav>

</li>

</ul>
Expand Down Expand Up @@ -563,6 +596,39 @@
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#string-interpolation" class="md-nav__link">
<span class="md-ellipsis">
String Interpolation
</span>
</a>

<nav class="md-nav" aria-label="String Interpolation">
<ul class="md-nav__list">

<li class="md-nav__item">
<a href="#environment-variables" class="md-nav__link">
<span class="md-ellipsis">
Environment Variables
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#self-configuration-reference" class="md-nav__link">
<span class="md-ellipsis">
Self Configuration Reference
</span>
</a>

</li>

</ul>
</nav>

</li>

</ul>
Expand Down Expand Up @@ -615,6 +681,18 @@ <h2 id="nested-configurations">Nested Configurations</h2>
<a id="__codelineno-2-8" name="__codelineno-2-8" href="#__codelineno-2-8"></a><span class="n">nested_config</span> <span class="o">=</span> <span class="n">load_config</span><span class="p">(</span><span class="n">NestedConfiguration</span><span class="p">)</span>
</code></pre></div>
<p><code>load_config()</code> populates every field, including <code>nested_config.nested.inner_hello</code>. The default prefix for every field in <code>Inner</code> is <code>nested</code>, which can be changed with <code>Annotated[Inner, Prefixed("new_prefix")]</code>.</p>
<h2 id="string-interpolation">String Interpolation</h2>
<h3 id="environment-variables">Environment Variables</h3>
<p>For configuration files, environment variables are used to fill string templates. For example, if your config contains <code>${TEST_VALUE}</code>, the value is fetched from the TEST_VALUE environment variable. This also supports lists and dictionaries, such as <code>["${TEST_VALUE}", "world"]</code> and <code>{"key": "${TEST_VALUE}", "key2": "world"}</code>.</p>
<h3 id="self-configuration-reference">Self Configuration Reference</h3>
<p>Self-reference works by replacing values from the same configuration source it is reading. For example, if your config contains:
<div class="highlight"><pre><span></span><code><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="p">{</span>
<a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a><span class="w"> </span><span class="nt">&quot;host&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;localhost&quot;</span><span class="p">,</span>
<a id="__codelineno-3-3" name="__codelineno-3-3" href="#__codelineno-3-3"></a><span class="w"> </span><span class="nt">&quot;port&quot;</span><span class="p">:</span><span class="w"> </span><span class="mi">8080</span><span class="p">,</span>
<a id="__codelineno-3-4" name="__codelineno-3-4" href="#__codelineno-3-4"></a><span class="w"> </span><span class="nt">&quot;url&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;http://${self.host}:${self.port}&quot;</span>
<a id="__codelineno-3-5" name="__codelineno-3-5" href="#__codelineno-3-5"></a><span class="p">}</span>
</code></pre></div>
The url gets populated with the host and port defined in the source.</p>



Expand Down
2 changes: 1 addition & 1 deletion essex-config/sources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ <h1 id="sources">Sources</h1>
</ol>
<p>Example of multiple sources:</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="kn">from</span> <span class="nn">pydantic</span> <span class="kn">import</span> <span class="n">BaseModel</span><span class="p">,</span> <span class="n">Field</span>
<a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="kn">from</span> <span class="nn">essex_config</span> <span class="kn">import</span> <span class="n">config</span>
<a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="kn">from</span> <span class="nn">essex_config</span> <span class="kn">import</span> <span class="n">load_config</span>
<a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a><span class="kn">from</span> <span class="nn">essex_config.sources</span> <span class="kn">import</span> <span class="n">EnvSource</span><span class="p">,</span> <span class="n">FileSource</span><span class="p">,</span> <span class="n">KeyVaultSource</span>
<a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a>
<a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a><span class="k">class</span> <span class="nc">CustomerDatabase</span><span class="p">(</span><span class="n">Config</span><span class="p">):</span>
Expand Down
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

Binary file modified sitemap.xml.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion storybook/project.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"generatedAt":1728058556203,"hasCustomBabel":false,"hasCustomWebpack":true,"hasStaticDirs":true,"hasStorybookEslint":false,"refCount":0,"monorepo":"Turborepo","packageManager":{"type":"yarn","version":"4.3.1"},"typescriptOptions":{"reactDocgen":"react-docgen-typescript","reactDocgenTypescriptOptions":{"compilerOptions":{"allowSyntheticDefaultImports":false,"esModuleInterop":false}}},"preview":{"usesGlobals":false},"framework":{"name":"@storybook/react-webpack5","options":{}},"builder":"@storybook/builder-webpack5","renderer":"@storybook/react","storybookVersion":"7.3.2","storybookVersionSpecifier":"7.3.2","language":"typescript","storybookPackages":{"@essex/storybook-config":{"version":null},"@storybook/addon-a11y":{"version":"7.3.2"},"@storybook/addon-docs":{"version":"7.3.2"},"@storybook/addon-links":{"version":"7.3.2"},"@storybook/addons":{"version":"7.3.2"},"@storybook/client-api":{"version":"7.3.2"},"@storybook/core-events":{"version":"7.3.2"},"@storybook/react":{"version":"7.3.2"},"@storybook/react-webpack5":{"version":"7.3.2"},"@storybook/theming":{"version":"7.3.2"},"storybook":{"version":"7.3.2"}},"addons":{"$SNIP/.yarn/__virtual__/@storybook-addon-links-virtual-8e40d1bf5a/0/cache/@storybook-addon-links-npm-7.3.2-223e7580c8-78df2eef13.zip/node_modules/@storybook/addon-links":{"version":null},"@storybook/addon-essentials":{"version":"7.3.2"},"@storybook/addon-interactions":{"version":"7.3.2"}}}
{"generatedAt":1728496572351,"hasCustomBabel":false,"hasCustomWebpack":true,"hasStaticDirs":true,"hasStorybookEslint":false,"refCount":0,"monorepo":"Turborepo","packageManager":{"type":"yarn","version":"4.3.1"},"typescriptOptions":{"reactDocgen":"react-docgen-typescript","reactDocgenTypescriptOptions":{"compilerOptions":{"allowSyntheticDefaultImports":false,"esModuleInterop":false}}},"preview":{"usesGlobals":false},"framework":{"name":"@storybook/react-webpack5","options":{}},"builder":"@storybook/builder-webpack5","renderer":"@storybook/react","storybookVersion":"7.3.2","storybookVersionSpecifier":"7.3.2","language":"typescript","storybookPackages":{"@essex/storybook-config":{"version":null},"@storybook/addon-a11y":{"version":"7.3.2"},"@storybook/addon-docs":{"version":"7.3.2"},"@storybook/addon-links":{"version":"7.3.2"},"@storybook/addons":{"version":"7.3.2"},"@storybook/client-api":{"version":"7.3.2"},"@storybook/core-events":{"version":"7.3.2"},"@storybook/react":{"version":"7.3.2"},"@storybook/react-webpack5":{"version":"7.3.2"},"@storybook/theming":{"version":"7.3.2"},"storybook":{"version":"7.3.2"}},"addons":{"$SNIP/.yarn/__virtual__/@storybook-addon-links-virtual-8e40d1bf5a/0/cache/@storybook-addon-links-npm-7.3.2-223e7580c8-78df2eef13.zip/node_modules/@storybook/addon-links":{"version":null},"@storybook/addon-essentials":{"version":"7.3.2"},"@storybook/addon-interactions":{"version":"7.3.2"}}}

0 comments on commit 502ab69

Please sign in to comment.