Skip to content

Commit

Permalink
deploy: 18ce6aa
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-ashkinaze committed Dec 22, 2024
1 parent abecc5c commit 36e6541
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
23 changes: 8 additions & 15 deletions _modules/plurals/helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -497,26 +497,19 @@ <h1>Source code for plurals.helpers</h1><div class="highlight"><pre>
<div class="viewcode-block" id="get_resource_path">
<a class="viewcode-back" href="../../helpers.html#plurals.helpers.get_resource_path">[docs]</a>
<span class="k">def</span> <span class="nf">get_resource_path</span><span class="p">(</span><span class="n">package</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">resource</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Get the path to a resource file, supporting both pkg_resources and importlib.resources.</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Get the path to a resource file, supporting both pkg_resources and importlib.resources.</span>
<span class="sd"> Falls back to importlib.resources if pkg_resources is not available.</span>

<span class="sd"> Problem this solves:</span>
<span class="sd"> - In python 3.12, pkg_resources is being deprecated in favor of importlib.resources, and</span>
<span class="sd"> it no longer comes with pkg_resources. This creates an import error unless user does `pip install setuptools` but it is</span>
<span class="sd"> bad practice to add setuptools as a runtime dependency.</span>

<span class="sd"> - If I just switch to importlib, this is limiting since importlib is only for 3.9+.</span>

<span class="sd"> - So the solution is to use pkg_resources if available, and if not, use importlib.resources.</span>

<span class="sd"> - In python 3.12, pkg_resources is being deprecated in favor of importlib.resources, and</span>
<span class="sd"> it no longer comes with pkg_resources. This creates an import error unless user does</span>
<span class="sd"> `pip install setuptools` but it is bad practice to add setuptools as a runtime dependency.</span>
<span class="sd"> - If I just switch to importlib, this is limiting since importlib is only for 3.9+.</span>
<span class="sd"> - So the solution is to use pkg_resources if available, and if not, use importlib.resources.</span>

<span class="sd"> Args:</span>
<span class="sd"> package: The package name (just __name__ usually)</span>
<span class="sd"> resource: The resource path relative to the package</span>

<span class="sd"> Returns:</span>
<span class="sd"> str: The full path to the resource</span>
<span class="sd"> package (str): The package name (just __name__ usually)</span>
<span class="sd"> resource (str): The resource path relative to the package</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">pkg_resources</span>
Expand Down
22 changes: 9 additions & 13 deletions helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -449,27 +449,23 @@ <h3>3. None Replacement<a class="headerlink" href="#none-replacement" title="Lin
<span class="sig-prename descclassname"><span class="pre">plurals.helpers.</span></span><span class="sig-name descname"><span class="pre">get_resource_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">package</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">resource</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">str</span></span></span><a class="reference internal" href="_modules/plurals/helpers.html#get_resource_path"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#plurals.helpers.get_resource_path" title="Link to this definition">#</a></dt>
<dd><p>Get the path to a resource file, supporting both pkg_resources and importlib.resources.
Falls back to importlib.resources if pkg_resources is not available.</p>
<p>Problem this solves:
- In python 3.12, pkg_resources is being deprecated in favor of importlib.resources, and
it no longer comes with pkg_resources. This creates an import error unless user does <cite>pip install setuptools</cite> but it is
bad practice to add setuptools as a runtime dependency.</p>
<ul class="simple">
<dl class="simple">
<dt>Problem this solves:</dt><dd><ul class="simple">
<li><p>In python 3.12, pkg_resources is being deprecated in favor of importlib.resources, and
it no longer comes with pkg_resources. This creates an import error unless user does
<cite>pip install setuptools</cite> but it is bad practice to add setuptools as a runtime dependency.</p></li>
<li><p>If I just switch to importlib, this is limiting since importlib is only for 3.9+.</p></li>
<li><p>So the solution is to use pkg_resources if available, and if not, use importlib.resources.</p></li>
</ul>
</dd>
</dl>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>package</strong> – The package name (just __name__ usually)</p></li>
<li><p><strong>resource</strong> – The resource path relative to the package</p></li>
<li><p><strong>package</strong> (<em>str</em>) – The package name (just __name__ usually)</p></li>
<li><p><strong>resource</strong> (<em>str</em>) – The resource path relative to the package</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>The full path to the resource</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>str</p>
</dd>
</dl>
</dd></dl>

Expand Down

0 comments on commit 36e6541

Please sign in to comment.