-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't open orphan path on bare importlib.resources.files() under zipapp #121735
Comments
this version was in the recent 0.21.0 release and worked fine the irc library is broken (for us) since jaraco/irc@c95c063 the reason is that it uses importlib.resources.files() to import codes and this function is buggy -- it doesn't work with freezed code (see also python/cpython#121735. wimglenn/resources-example#6) and (what a coincidence!) broken implementation of files() function was written by the same person -- see python/cpython#100598
ping @jaraco in case you missed this one |
The code that handles the module inference is here: cpython/Lib/importlib/resources/_common.py Lines 75 to 104 in 6ae942f
Next step is to determine what expectation is missed when running under zipapp. |
I was able to replicate the issue without going through the wheel build process: draft 🐚 mkdir -p buildtemp/mypkg
draft 🐚 cat > buildtemp/mypkg/a.py
import importlib.resources
def main():
x = importlib.resources.files() / "data.txt"
print(x.read_text())
draft 🐚 echo datadata > buildtemp/mypkg/data.txt
draft 🐚 py -m zipapp buildtemp --main mypkg.a:main -p '/usr/bin/env py' -o mypkg.pyz
draft 🐚 ./mypkg.pyz
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/jaraco/draft/./mypkg.pyz/__main__.py", line 3, in <module>
mypkg.a.main()
~~~~~~~~~~~~^^
File "/Users/jaraco/draft/./mypkg.pyz/mypkg/a.py", line 6, in main
print(x.read_text())
~~~~~~~~~~~^^
File "/opt/python/lib/python3.13/importlib/resources/abc.py", line 89, in read_text
with self.open(encoding=encoding) as strm:
~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/opt/python/lib/python3.13/importlib/resources/_adapters.py", line 139, in open
raise FileNotFoundError("Can't open orphan path")
FileNotFoundError: Can't open orphan path |
The issue is that
|
It's clear that the bare call to
By changing the def main():
print(importlib.resources._common._infer_caller().f_globals['__name__']) I can confirm that the inferred name is correct when it emits Interestingly, if I then replace the main function with a static 'mypkg.a', the reported error occurs. def main():
x = importlib.resources.files('mypkg.a') / "data.txt"
print(x.read_text()) So the issue seems to be that
It seems that the (Pdb) importlib.import_module('mypkg.a').__spec__.loader.get_resource_reader('mypkg.a')
(Pdb) importlib.import_module('mypkg.a').__spec__.loader.get_resource_reader('mypkg')
(Pdb) importlib.import_module('mypkg').__spec__.loader.get_resource_reader('mypkg')
<importlib.resources.readers.NamespaceReader object at 0x3df2e585410> I'm slightly surprised to see |
It seems the issue traces to the logic in get_resource_reader: Lines 258 to 270 in 6ae942f
When checking (Pdb) loader = importlib.import_module('mypkg.a').__spec__.loader
(Pdb) loader.is_package('mypkg.a')
False In the early days of importlib.resources, all resources needed to be relative to a package (and not a module). Later, that restriction was relaxed to allow resources to be loaded relative to a module. But it seems that I've confirmed the same issue occurs when using
I suspect the resolution is going to be update But first things first, let's figure out why this use-case isn't covered by the tests. |
As a check, if I remove the cpython main 🐚 git diff
diff --git a/Lib/zipimport.py b/Lib/zipimport.py
index f2724dd0268..c0a4abcd95d 100644
--- a/Lib/zipimport.py
+++ b/Lib/zipimport.py
@@ -256,16 +256,8 @@ def load_module(self, fullname):
def get_resource_reader(self, fullname):
- """Return the ResourceReader for a package in a zip file.
-
- If 'fullname' is a package within the zip file, return the
- 'ResourceReader' object for the package. Otherwise return None.
+ """Return the ResourceReader for a module in a zip file.
"""
- try:
- if not self.is_package(fullname):
- return None
- except ZipImportError:
- return None
from importlib.readers import ZipReader
return ZipReader(self, fullname) The routine then fails, but with a different error: draft 🐚 ./mypkg.pyz
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/jaraco/draft/./mypkg.pyz/__main__.py", line 3, in <module>
mypkg.a.main()
~~~~~~~~~~~~^^
File "/Users/jaraco/draft/./mypkg.pyz/mypkg/a.py", line 6, in main
print(x.read_text())
~~~~~~~~~~~^^
File "/Users/jaraco/code/python/cpython/Lib/zipfile/_path/__init__.py", line 426, in read_text
with self.open('r', encoding, *args, **kwargs) as strm:
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jaraco/code/python/cpython/Lib/zipfile/_path/__init__.py", line 391, in open
raise FileNotFoundError(self)
FileNotFoundError: /Users/jaraco/draft/./mypkg.pyz/mypkg/a/data.txt That's encouraging, suggesting that the |
I started working on a test, seeking to extend these tests to zip files, but realized that the current test structure isn't easily amenable to extension to zip. In python/importlib_resources@3faf336, I've done some refactoring in order to leverage the zip fixtures for this purpose. |
Module files zip tests is marked as xfail due to the issue reported in python/cpython#121735.
Module files zip tests is marked as xfail due to the issue reported in python/cpython#121735.
I'm releasing |
Quick turnaround, thank you. If I understand devguide correctly, miss-islington should presumably backport the CPython change into 3.12.x as bugfix (but not any earlier versions)? |
That's right. And I think it was 3.12 that introduced this feature, so there shouldn't be any users of earlier versions expecting anything different. |
I've nearly got the feature ported, but there's a failure in one of the new tests (ImplicitContextFileZipTests.test_implicit_files_submodule):
Somehow the |
But when I inspect the reader directly, everything looks fine:
So I'm stumped as to why the same call fails from |
I think I found the issue - a lingering |
Yes, that's all it was (whew!). |
…ces.files() without anchor
… name which is inside that package
Bumps [importlib-resources](https://github.com/python/importlib_resources) from 6.4.0 to 6.4.3. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/python/importlib_resources/blob/main/NEWS.rst">importlib-resources's changelog</a>.</em></p> <blockquote> <h1>v6.4.3</h1> <h2>Bugfixes</h2> <ul> <li>When inferring the caller in <code>files()</code><code>python/cpython#123085</code></li> </ul> <h1>v6.4.2</h1> <h2>Bugfixes</h2> <ul> <li>Merged fix for UTF-16 BOM handling in functional tests. (<a href="https://redirect.github.com/python/importlib_resources/issues/312">#312</a>)</li> </ul> <h1>v6.4.1</h1> <h2>Bugfixes</h2> <ul> <li><code>python/cpython#121735</code></li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/python/importlib_resources/commit/d02141768b62468e46064614276036ea5c746056"><code>d021417</code></a> Finalize</li> <li><a href="https://github.com/python/importlib_resources/commit/0ecbc3b374ae84ae10ded5e1ad1d8775e12c2dd7"><code>0ecbc3b</code></a> Merge pull request <a href="https://redirect.github.com/python/importlib_resources/issues/314">#314</a> from python/<a href="https://redirect.github.com/python/importlib_resources/issues/123085">gh-123085</a>/inferred-compiled</li> <li><a href="https://github.com/python/importlib_resources/commit/79fa62f4b5cbf8f358560651a714b282aee2226c"><code>79fa62f</code></a> Add docstring and reference to the issue.</li> <li><a href="https://github.com/python/importlib_resources/commit/90c0e420ef15256f116342c97ea984a2fa604cc3"><code>90c0e42</code></a> Rely on <code>resources.__name__</code> for easier portability.</li> <li><a href="https://github.com/python/importlib_resources/commit/d618902dbe0e9f94e634a95bc9bbaf941236fc0c"><code>d618902</code></a> Add news fragment.</li> <li><a href="https://github.com/python/importlib_resources/commit/ebc5b97ffe1d20eb6ebc536dd1f6b385f83652a5"><code>ebc5b97</code></a> Extract the filename from the topmost frame of the stack.</li> <li><a href="https://github.com/python/importlib_resources/commit/4ea81bf920f6cc6377ccc7fbc1f4f343927f4f20"><code>4ea81bf</code></a> Extract a function for computing 'this filename' once.</li> <li><a href="https://github.com/python/importlib_resources/commit/cba8dce7839977c66806ef05e122cf38ed14a113"><code>cba8dce</code></a> Adapt changes for new fixtures.</li> <li><a href="https://github.com/python/importlib_resources/commit/198adec064edf0c10aac45ab85c68535ba038a59"><code>198adec</code></a> <a href="https://redirect.github.com/python/importlib_resources/issues/121735">gh-121735</a>: Fix inferring caller when resolving importlib.resources.files()</li> <li><a href="https://github.com/python/importlib_resources/commit/21afd614ce6976b43185a0931f988ea81862eb8d"><code>21afd61</code></a> Merge changes to syncronize the 6.4 release with downstream CPython changes.</li> <li>Additional commits viewable in <a href="https://github.com/python/importlib_resources/compare/v6.4.0...v6.4.3">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=importlib-resources&package-manager=pip&previous-version=6.4.0&new-version=6.4.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [importlib-resources](https://github.com/python/importlib_resources) from 6.1.1 to 6.4.3. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/python/importlib_resources/blob/main/NEWS.rst">importlib-resources's changelog</a>.</em></p> <blockquote> <h1>v6.4.3</h1> <h2>Bugfixes</h2> <ul> <li>When inferring the caller in <code>files()</code><code>python/cpython#123085</code></li> </ul> <h1>v6.4.2</h1> <h2>Bugfixes</h2> <ul> <li>Merged fix for UTF-16 BOM handling in functional tests. (<a href="https://redirect.github.com/python/importlib_resources/issues/312">#312</a>)</li> </ul> <h1>v6.4.1</h1> <h2>Bugfixes</h2> <ul> <li><code>python/cpython#121735</code></li> </ul> <h1>v6.4.0</h1> <h2>Features</h2> <ul> <li>The functions <code>is_resource()</code>, <code>open_binary()</code>, <code>open_text()</code>, <code>path()</code>, <code>read_binary()</code>, and <code>read_text()</code> are un-deprecated, and support subdirectories via multiple positional arguments. The <code>contents()</code> function also allows subdirectories, but remains deprecated. (<a href="https://redirect.github.com/python/importlib_resources/issues/303">#303</a>)</li> <li><code>python/cpython#109829</code></li> </ul> <h1>v6.3.2</h1> <p>Bugfixes</p> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/python/importlib_resources/commit/d02141768b62468e46064614276036ea5c746056"><code>d021417</code></a> Finalize</li> <li><a href="https://github.com/python/importlib_resources/commit/0ecbc3b374ae84ae10ded5e1ad1d8775e12c2dd7"><code>0ecbc3b</code></a> Merge pull request <a href="https://redirect.github.com/python/importlib_resources/issues/314">#314</a> from python/<a href="https://redirect.github.com/python/importlib_resources/issues/123085">gh-123085</a>/inferred-compiled</li> <li><a href="https://github.com/python/importlib_resources/commit/79fa62f4b5cbf8f358560651a714b282aee2226c"><code>79fa62f</code></a> Add docstring and reference to the issue.</li> <li><a href="https://github.com/python/importlib_resources/commit/90c0e420ef15256f116342c97ea984a2fa604cc3"><code>90c0e42</code></a> Rely on <code>resources.__name__</code> for easier portability.</li> <li><a href="https://github.com/python/importlib_resources/commit/d618902dbe0e9f94e634a95bc9bbaf941236fc0c"><code>d618902</code></a> Add news fragment.</li> <li><a href="https://github.com/python/importlib_resources/commit/ebc5b97ffe1d20eb6ebc536dd1f6b385f83652a5"><code>ebc5b97</code></a> Extract the filename from the topmost frame of the stack.</li> <li><a href="https://github.com/python/importlib_resources/commit/4ea81bf920f6cc6377ccc7fbc1f4f343927f4f20"><code>4ea81bf</code></a> Extract a function for computing 'this filename' once.</li> <li><a href="https://github.com/python/importlib_resources/commit/cba8dce7839977c66806ef05e122cf38ed14a113"><code>cba8dce</code></a> Adapt changes for new fixtures.</li> <li><a href="https://github.com/python/importlib_resources/commit/198adec064edf0c10aac45ab85c68535ba038a59"><code>198adec</code></a> <a href="https://redirect.github.com/python/importlib_resources/issues/121735">gh-121735</a>: Fix inferring caller when resolving importlib.resources.files()</li> <li><a href="https://github.com/python/importlib_resources/commit/21afd614ce6976b43185a0931f988ea81862eb8d"><code>21afd61</code></a> Merge changes to syncronize the 6.4 release with downstream CPython changes.</li> <li>Additional commits viewable in <a href="https://github.com/python/importlib_resources/compare/v6.1.1...v6.4.3">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=importlib-resources&package-manager=pip&previous-version=6.1.1&new-version=6.4.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [importlib-resources](https://github.com/python/importlib_resources) from 6.4.0 to 6.4.3. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/python/importlib_resources/blob/main/NEWS.rst">importlib-resources's changelog</a>.</em></p> <blockquote> <h1>v6.4.3</h1> <h2>Bugfixes</h2> <ul> <li>When inferring the caller in <code>files()</code><code>python/cpython#123085</code></li> </ul> <h1>v6.4.2</h1> <h2>Bugfixes</h2> <ul> <li>Merged fix for UTF-16 BOM handling in functional tests. (<a href="https://redirect.github.com/python/importlib_resources/issues/312">#312</a>)</li> </ul> <h1>v6.4.1</h1> <h2>Bugfixes</h2> <ul> <li><code>python/cpython#121735</code></li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/python/importlib_resources/commit/d02141768b62468e46064614276036ea5c746056"><code>d021417</code></a> Finalize</li> <li><a href="https://github.com/python/importlib_resources/commit/0ecbc3b374ae84ae10ded5e1ad1d8775e12c2dd7"><code>0ecbc3b</code></a> Merge pull request <a href="https://redirect.github.com/python/importlib_resources/issues/314">#314</a> from python/<a href="https://redirect.github.com/python/importlib_resources/issues/123085">gh-123085</a>/inferred-compiled</li> <li><a href="https://github.com/python/importlib_resources/commit/79fa62f4b5cbf8f358560651a714b282aee2226c"><code>79fa62f</code></a> Add docstring and reference to the issue.</li> <li><a href="https://github.com/python/importlib_resources/commit/90c0e420ef15256f116342c97ea984a2fa604cc3"><code>90c0e42</code></a> Rely on <code>resources.__name__</code> for easier portability.</li> <li><a href="https://github.com/python/importlib_resources/commit/d618902dbe0e9f94e634a95bc9bbaf941236fc0c"><code>d618902</code></a> Add news fragment.</li> <li><a href="https://github.com/python/importlib_resources/commit/ebc5b97ffe1d20eb6ebc536dd1f6b385f83652a5"><code>ebc5b97</code></a> Extract the filename from the topmost frame of the stack.</li> <li><a href="https://github.com/python/importlib_resources/commit/4ea81bf920f6cc6377ccc7fbc1f4f343927f4f20"><code>4ea81bf</code></a> Extract a function for computing 'this filename' once.</li> <li><a href="https://github.com/python/importlib_resources/commit/cba8dce7839977c66806ef05e122cf38ed14a113"><code>cba8dce</code></a> Adapt changes for new fixtures.</li> <li><a href="https://github.com/python/importlib_resources/commit/198adec064edf0c10aac45ab85c68535ba038a59"><code>198adec</code></a> <a href="https://redirect.github.com/python/importlib_resources/issues/121735">gh-121735</a>: Fix inferring caller when resolving importlib.resources.files()</li> <li><a href="https://github.com/python/importlib_resources/commit/21afd614ce6976b43185a0931f988ea81862eb8d"><code>21afd61</code></a> Merge changes to syncronize the 6.4 release with downstream CPython changes.</li> <li>Additional commits viewable in <a href="https://github.com/python/importlib_resources/compare/v6.4.0...v6.4.3">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=importlib-resources&package-manager=pip&previous-version=6.4.0&new-version=6.4.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Charles Guo <[email protected]>
Bumps [importlib-resources](https://github.com/python/importlib_resources) from 6.1.1 to 6.4.4. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/python/importlib_resources/blob/main/NEWS.rst">importlib-resources's changelog</a>.</em></p> <blockquote> <h1>v6.4.4</h1> <p>No significant changes.</p> <h1>v6.4.3</h1> <h2>Bugfixes</h2> <ul> <li>When inferring the caller in <code>files()</code><code>python/cpython#123085</code></li> </ul> <h1>v6.4.2</h1> <h2>Bugfixes</h2> <ul> <li>Merged fix for UTF-16 BOM handling in functional tests. (<a href="https://redirect.github.com/python/importlib_resources/issues/312">#312</a>)</li> </ul> <h1>v6.4.1</h1> <h2>Bugfixes</h2> <ul> <li><code>python/cpython#121735</code></li> </ul> <h1>v6.4.0</h1> <h2>Features</h2> <ul> <li>The functions <code>is_resource()</code>, <code>open_binary()</code>, <code>open_text()</code>, <code>path()</code>, <code>read_binary()</code>, and <code>read_text()</code> are un-deprecated, and support subdirectories via multiple positional arguments. The <code>contents()</code> function also allows subdirectories, but remains deprecated. (<a href="https://redirect.github.com/python/importlib_resources/issues/303">#303</a>)</li> <li><code>python/cpython#109829</code></li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/python/importlib_resources/commit/9689f8f82ca838cd58d3d0d80828785ada7798c9"><code>9689f8f</code></a> Finalize</li> <li><a href="https://github.com/python/importlib_resources/commit/f3ad28a14feb85dc2631a8e3658f090ed0b7522d"><code>f3ad28a</code></a> 🧎♀️ Genuflect to the types.</li> <li><a href="https://github.com/python/importlib_resources/commit/045dde42b16581b99539667a87d61252bf4d08ac"><code>045dde4</code></a> 🧎♀️ Genuflect to the types.</li> <li><a href="https://github.com/python/importlib_resources/commit/2fecb5e596c7b6ff2d3f98af0ac63c9f38401c5a"><code>2fecb5e</code></a> 🧎♀️ Genuflect to the types.</li> <li><a href="https://github.com/python/importlib_resources/commit/75b301c95ce3d75626c949a26e650deceba8e62c"><code>75b301c</code></a> 🧎♀️ Genuflect to the types.</li> <li><a href="https://github.com/python/importlib_resources/commit/45167451781dd8fc03e5568da40144dd8a4f790d"><code>4516745</code></a> Merge <a href="https://github.com/jaraco/skeleton">https://github.com/jaraco/skeleton</a></li> <li><a href="https://github.com/python/importlib_resources/commit/f1350e413775a9e79e20779cc9705e28a1c55900"><code>f1350e4</code></a> Add upstream and local sections for 'type' extra, since many projects will ha...</li> <li><a href="https://github.com/python/importlib_resources/commit/d02141768b62468e46064614276036ea5c746056"><code>d021417</code></a> Finalize</li> <li><a href="https://github.com/python/importlib_resources/commit/0ecbc3b374ae84ae10ded5e1ad1d8775e12c2dd7"><code>0ecbc3b</code></a> Merge pull request <a href="https://redirect.github.com/python/importlib_resources/issues/314">#314</a> from python/<a href="https://redirect.github.com/python/importlib_resources/issues/123085">gh-123085</a>/inferred-compiled</li> <li><a href="https://github.com/python/importlib_resources/commit/79fa62f4b5cbf8f358560651a714b282aee2226c"><code>79fa62f</code></a> Add docstring and reference to the issue.</li> <li>Additional commits viewable in <a href="https://github.com/python/importlib_resources/compare/v6.1.1...v6.4.4">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=importlib-resources&package-manager=pip&previous-version=6.1.1&new-version=6.4.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [importlib-resources](https://github.com/python/importlib_resources) from 5.13.0 to 6.4.4. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/python/importlib_resources/blob/main/NEWS.rst">importlib-resources's changelog</a>.</em></p> <blockquote> <h1>v6.4.4</h1> <p>No significant changes.</p> <h1>v6.4.3</h1> <h2>Bugfixes</h2> <ul> <li>When inferring the caller in <code>files()</code><code>python/cpython#123085</code></li> </ul> <h1>v6.4.2</h1> <h2>Bugfixes</h2> <ul> <li>Merged fix for UTF-16 BOM handling in functional tests. (<a href="https://redirect.github.com/python/importlib_resources/issues/312">#312</a>)</li> </ul> <h1>v6.4.1</h1> <h2>Bugfixes</h2> <ul> <li><code>python/cpython#121735</code></li> </ul> <h1>v6.4.0</h1> <h2>Features</h2> <ul> <li>The functions <code>is_resource()</code>, <code>open_binary()</code>, <code>open_text()</code>, <code>path()</code>, <code>read_binary()</code>, and <code>read_text()</code> are un-deprecated, and support subdirectories via multiple positional arguments. The <code>contents()</code> function also allows subdirectories, but remains deprecated. (<a href="https://redirect.github.com/python/importlib_resources/issues/303">#303</a>)</li> <li><code>python/cpython#109829</code></li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/python/importlib_resources/commit/9689f8f82ca838cd58d3d0d80828785ada7798c9"><code>9689f8f</code></a> Finalize</li> <li><a href="https://github.com/python/importlib_resources/commit/f3ad28a14feb85dc2631a8e3658f090ed0b7522d"><code>f3ad28a</code></a> 🧎♀️ Genuflect to the types.</li> <li><a href="https://github.com/python/importlib_resources/commit/045dde42b16581b99539667a87d61252bf4d08ac"><code>045dde4</code></a> 🧎♀️ Genuflect to the types.</li> <li><a href="https://github.com/python/importlib_resources/commit/2fecb5e596c7b6ff2d3f98af0ac63c9f38401c5a"><code>2fecb5e</code></a> 🧎♀️ Genuflect to the types.</li> <li><a href="https://github.com/python/importlib_resources/commit/75b301c95ce3d75626c949a26e650deceba8e62c"><code>75b301c</code></a> 🧎♀️ Genuflect to the types.</li> <li><a href="https://github.com/python/importlib_resources/commit/45167451781dd8fc03e5568da40144dd8a4f790d"><code>4516745</code></a> Merge <a href="https://github.com/jaraco/skeleton">https://github.com/jaraco/skeleton</a></li> <li><a href="https://github.com/python/importlib_resources/commit/f1350e413775a9e79e20779cc9705e28a1c55900"><code>f1350e4</code></a> Add upstream and local sections for 'type' extra, since many projects will ha...</li> <li><a href="https://github.com/python/importlib_resources/commit/d02141768b62468e46064614276036ea5c746056"><code>d021417</code></a> Finalize</li> <li><a href="https://github.com/python/importlib_resources/commit/0ecbc3b374ae84ae10ded5e1ad1d8775e12c2dd7"><code>0ecbc3b</code></a> Merge pull request <a href="https://redirect.github.com/python/importlib_resources/issues/314">#314</a> from python/<a href="https://redirect.github.com/python/importlib_resources/issues/123085">gh-123085</a>/inferred-compiled</li> <li><a href="https://github.com/python/importlib_resources/commit/79fa62f4b5cbf8f358560651a714b282aee2226c"><code>79fa62f</code></a> Add docstring and reference to the issue.</li> <li>Additional commits viewable in <a href="https://github.com/python/importlib_resources/compare/v5.13.0...v6.4.4">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=importlib-resources&package-manager=pip&previous-version=5.13.0&new-version=6.4.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jesse Claven <[email protected]>
* gh-116608: Apply style and compatibility changes from importlib_metadata. * gh-121735: Ensure module-adjacent resources are loadable from a zipfile. * gh-121735: Allow all modules to be processed by the ZipReader. * Add blurb * Remove update-zips script, unneeded. * Remove unnecessary references to removed static fixtures. * Remove zipdata fixtures, unused.
…H-123037) * pythongh-116608: Apply style and compatibility changes from importlib_metadata. * pythongh-121735: Ensure module-adjacent resources are loadable from a zipfile. * pythongh-121735: Allow all modules to be processed by the ZipReader. * Add blurb * Remove update-zips script, unneeded. * Remove unnecessary references to removed static fixtures. * Remove zipdata fixtures, unused. (cherry picked from commit ba687d9) Co-authored-by: Jason R. Coombs <[email protected]>
…ythonGH-123037) * pythongh-116608: Apply style and compatibility changes from importlib_metadata. * pythongh-121735: Ensure module-adjacent resources are loadable from a zipfile. * pythongh-121735: Allow all modules to be processed by the ZipReader. * Add blurb * Remove update-zips script, unneeded. * Remove unnecessary references to removed static fixtures. * Remove zipdata fixtures, unused. (cherry picked from commit ba687d9) Co-authored-by: Jason R. Coombs <[email protected]>
…ythonGH-123037) * pythongh-116608: Apply style and compatibility changes from importlib_metadata. * pythongh-121735: Ensure module-adjacent resources are loadable from a zipfile. * pythongh-121735: Allow all modules to be processed by the ZipReader. * Add blurb * Remove update-zips script, unneeded. * Remove unnecessary references to removed static fixtures. * Remove zipdata fixtures, unused. (cherry picked from commit ba687d9) Co-authored-by: Jason R. Coombs <[email protected]>
Applying the fix only and not the refactoring of the test suite.
Applying the fix only and not the refactoring of the test suite.
) (#123986) * gh-121735: Fix module-adjacent references in zip files (GH-123037) * gh-116608: Apply style and compatibility changes from importlib_metadata. * gh-121735: Ensure module-adjacent resources are loadable from a zipfile. * gh-121735: Allow all modules to be processed by the ZipReader. * Add blurb * Remove update-zips script, unneeded. * Remove unnecessary references to removed static fixtures. * Remove zipdata fixtures, unused. (cherry picked from commit ba687d9) * gh-123994: Generate utf-16 file using little endian and BOM. (#123995) Co-authored-by: Jason R. Coombs <[email protected]>
[//]: # (dependabot-start)⚠️ **Dependabot is rebasing this PR**⚠️ Rebasing might not happen immediately, so don't worry if this takes some time. Note: if you make any changes to this PR yourself, they will take precedence over the rebase. --- [//]: # (dependabot-end) Bumps [importlib-resources](https://github.com/python/importlib_resources) from 6.1.3 to 6.4.5. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/python/importlib_resources/blob/main/NEWS.rst">importlib-resources's changelog</a>.</em></p> <blockquote> <h1>v6.4.5</h1> <h2>Bugfixes</h2> <ul> <li>Omit sentinel values from a namespace path. (<a href="https://redirect.github.com/python/importlib_resources/issues/311">#311</a>)</li> </ul> <h1>v6.4.4</h1> <p>No significant changes.</p> <h1>v6.4.3</h1> <h2>Bugfixes</h2> <ul> <li>When inferring the caller in <code>files()</code><code>python/cpython#123085</code></li> </ul> <h1>v6.4.2</h1> <h2>Bugfixes</h2> <ul> <li>Merged fix for UTF-16 BOM handling in functional tests. (<a href="https://redirect.github.com/python/importlib_resources/issues/312">#312</a>)</li> </ul> <h1>v6.4.1</h1> <h2>Bugfixes</h2> <ul> <li><code>python/cpython#121735</code></li> </ul> <h1>v6.4.0</h1> <h2>Features</h2> <ul> <li>The functions <code>is_resource()</code>,</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/python/importlib_resources/commit/284148b005b57031a354402c446473f53cab2c49"><code>284148b</code></a> Finalize</li> <li><a href="https://github.com/python/importlib_resources/commit/63a7bcba42e6222971edd91f49e7efffe1972f35"><code>63a7bcb</code></a> Merge pull request <a href="https://redirect.github.com/python/importlib_resources/issues/315">#315</a> from python/bugfix/311-non-path-namespace-paths</li> <li><a href="https://github.com/python/importlib_resources/commit/2c145c5b1ff95290794b2cb63e5c924e1847456d"><code>2c145c5</code></a> Omit sentinel values from a namespace path.</li> <li><a href="https://github.com/python/importlib_resources/commit/47d73b1e7787cd66ee57be676f2385d2183f78ac"><code>47d73b1</code></a> Add test capturing failure when resolving the MultiplexedPath for a namespace...</li> <li><a href="https://github.com/python/importlib_resources/commit/4875bc5179938324d157d9917b3a0bfb5fca8dd1"><code>4875bc5</code></a> Add type annotations for _candidate_paths</li> <li><a href="https://github.com/python/importlib_resources/commit/d84ca376316016420297fbc310ba181ca7d2864d"><code>d84ca37</code></a> Fix typo in _temp_path comment.</li> <li><a href="https://github.com/python/importlib_resources/commit/1a6fef299da3e0d6f74cb26e1d41fc0f13ed63ad"><code>1a6fef2</code></a> Merge <a href="https://github.com/jaraco/skeleton">https://github.com/jaraco/skeleton</a></li> <li><a href="https://github.com/python/importlib_resources/commit/790fa6e6feb9a93d39135494819b12e9df8a7bba"><code>790fa6e</code></a> Include the trailing slash in disable_error_code(overload-overlap), also requ...</li> <li><a href="https://github.com/python/importlib_resources/commit/2beb8b0c9d0f7046370e7c58c4e6baaf35154a16"><code>2beb8b0</code></a> Add support for linking usernames.</li> <li><a href="https://github.com/python/importlib_resources/commit/0c326f3f77b2420163f73d97f8fbd090fa49147d"><code>0c326f3</code></a> Add a degenerate nitpick_ignore for downstream consumers. Add a 'local' comme...</li> <li>Additional commits viewable in <a href="https://github.com/python/importlib_resources/compare/v6.1.3...v6.4.5">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=importlib-resources&package-manager=pip&previous-version=6.1.3&new-version=6.4.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bug report
Bug description:
Context: In Python 3.12 the function importlib.resources.files() was updated: https://docs.python.org/3/library/importlib.resources.html#importlib.resources.files
The Issue: When using
importlib.resources.files()
, I am able to open and read a text file included as package data in my package. However, if I zip up my package with zipapp and run the .pyz file, it is unable to read the text file.If I use
importlib.resources.files("mypkg")
it will work in both cases.Minimal example:
Create a project directory named
mypkg
with the src layout.Create the following files.
mypkg/src/mypkg/a.py
mypkg/src/mypkg/data.txt
In pyproject.toml make sure to set up the entry script and include the data file.
mypkg/pyproject.toml
Install the package into a fresh Python (virtual) environment with pip.
Run
myscript
and verify it printsdatadata
.Now back in the mypkg project root folder, we will generate a .pyz file with zipapp and run the program from the .pyz file.
Run
pip install . --target buildtemp --upgrade && python3 -m zipapp buildtemp --main mypkg.a:main -p '/usr/bin/env python3' -o mypkg.pyz
in the terminal.Run
./mypkg.pyz
. This results in an error:Note that if you change
x = importlib.resources.files() / "data.txt"
tox = importlib.resources.files("mypkg") / "data.txt"
, it will work when running the .pyz file.CPython versions tested on:
3.12
Operating systems tested on:
Linux, macOS
Linked PRs
The text was updated successfully, but these errors were encountered: