Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[3.12] gh-123085: Fix issue in inferred caller when resources package has no source (GH-123102) #124021

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

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch '3.12' into backport-a53812d-3.12
  • Loading branch information
jaraco authored Jan 5, 2025
commit 1f1afddfc1b6cf2a84e0d2a268f287792b9e2cc6
36 changes: 36 additions & 0 deletions 36 Lib/test/test_importlib/resources/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,42 @@ def test_implicit_files(self):
_path.build(spec, self.site_dir)
assert importlib.import_module('somepkg').val == 'resources are the best'

def test_implicit_files_zip_submodule(self):
"""
Special test for gh-121735 for Python 3.12.
"""
import os
import zipfile

def create_zip_from_directory(source_dir, zip_filename):
with zipfile.ZipFile(zip_filename, 'w') as zipf:
for root, _, files in os.walk(source_dir):
for file in files:
file_path = os.path.join(root, file)
# Ensure files are at the root
arcname = os.path.relpath(file_path, source_dir)
zipf.write(file_path, arcname)

set_val = textwrap.dedent(
"""
import importlib.resources as res
val = res.files().joinpath('res.txt').read_text(encoding='utf-8')
"""
)
spec = {
'somepkg': {
'__init__.py': set_val,
'submod.py': set_val,
'res.txt': 'resources are the best',
},
}
build_dir = self.fixtures.enter_context(os_helper.temp_dir())
_path.build(spec, build_dir)
zip_file = os.path.join(self.site_dir, 'thepkg.zip')
create_zip_from_directory(build_dir, zip_file)
self.fixtures.enter_context(import_helper.DirsOnSysPath(zip_file))
assert importlib.import_module('somepkg.submod').val == 'resources are the best'

def _compile_importlib(self):
"""
Make a compiled-only copy of the importlib resources package.
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.