Skip to content

Commit 330cfcd

Browse files
committed
[3.12] pythongh-121735: Fix module-adjacent references in zip files (pythonGH-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 <jaraco@jaraco.com>
1 parent 53af5b2 commit 330cfcd

38 files changed

+282
-294
lines changed

.gitattributes

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ Lib/test/cjkencodings/* noeol
2828
Lib/test/tokenizedata/coding20731.py noeol
2929
Lib/test/decimaltestdata/*.decTest noeol
3030
Lib/test/test_email/data/*.txt noeol
31-
Lib/test/test_importlib/resources/data01/* noeol
32-
Lib/test/test_importlib/resources/namespacedata01/* noeol
3331
Lib/test/xmltestdata/* noeol
3432

3533
# Shell scripts should have LF even on Windows because of Cygwin

Lib/importlib/resources/readers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ def files(self):
3131

3232
class ZipReader(abc.TraversableResources):
3333
def __init__(self, loader, module):
34-
_, _, name = module.rpartition('.')
35-
self.prefix = loader.prefix.replace('\\', '/') + name + '/'
34+
self.prefix = loader.prefix.replace('\\', '/')
35+
if loader.is_package(module):
36+
_, _, name = module.rpartition('.')
37+
self.prefix += name + '/'
3638
self.archive = loader.archive
3739

3840
def open_resource(self, resource):

Lib/test/test_importlib/resources/data01/__init__.py

Whitespace-only changes.
Binary file not shown.

Lib/test/test_importlib/resources/data01/subdirectory/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.

Lib/test/test_importlib/resources/data01/utf-8.file

Lines changed: 0 additions & 1 deletion
This file was deleted.

Lib/test/test_importlib/resources/data02/__init__.py

Whitespace-only changes.

Lib/test/test_importlib/resources/data02/one/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)