https://github.com/python/cpython/commit/e758eb301804936a5339e6e4a2af99cebc03fa83
commit: e758eb301804936a5339e6e4a2af99cebc03fa83
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: encukou <[email protected]>
date: 2025-01-07T12:28:03+01:00
summary:

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

gh-123085: _compile_importlib: Avoid copying sources before compilation 
(GH-124131)
(cherry picked from commit 42c8b0556c02d29e32f4c7c95e7128a343716250)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Jason R. Coombs <[email protected]>

files:
M Lib/test/test_importlib/resources/test_files.py

diff --git a/Lib/test/test_importlib/resources/test_files.py 
b/Lib/test/test_importlib/resources/test_files.py
index d34ea51b150f1e..489cc95d1d6fa5 100644
--- a/Lib/test/test_importlib/resources/test_files.py
+++ b/Lib/test/test_importlib/resources/test_files.py
@@ -150,18 +150,17 @@ def create_zip_from_directory(source_dir, zip_filename):
     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):

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to