Skip to content

[3.12] gh-123085: _compile_importlib: Avoid copying sources before compilation (GH-124131) #128581

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 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
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
15 changes: 7 additions & 8 deletions Lib/test/test_importlib/resources/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"""
Special test for gh-121735 for Python 3.12.
"""
import os

Check failure on line 118 in Lib/test/test_importlib/resources/test_files.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F811)

Lib/test/test_importlib/resources/test_files.py:118:16: F811 Redefinition of unused `os` from line 2
import zipfile

def create_zip_from_directory(source_dir, zip_filename):
Expand Down Expand Up @@ -150,18 +150,17 @@
def _compile_importlib(self):
"""
Make a compiled-only copy of the importlib resources package.

Currently only code is copied, as importlib resources doesn't itself
have any resources.
"""
bin_site = self.fixtures.enter_context(os_helper.temp_dir())
c_resources = pathlib.Path(bin_site, 'c_resources')
sources = pathlib.Path(resources.__file__).parent
shutil.copytree(sources, c_resources, ignore=lambda *_: ['__pycache__'])

for dirpath, _, filenames in os.walk(c_resources):
for filename in filenames:
source_path = pathlib.Path(dirpath) / filename
cfile = source_path.with_suffix('.pyc')
py_compile.compile(source_path, cfile)
pathlib.Path.unlink(source_path)

for source_path in sources.glob('**/*.py'):
c_path = c_resources.joinpath(source_path.relative_to(sources)).with_suffix('.pyc')
py_compile.compile(source_path, c_path)
self.fixtures.enter_context(import_helper.DirsOnSysPath(bin_site))

def test_implicit_files_with_compiled_importlib(self):
Expand Down
Loading