]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-123085: _compile_importlib: Avoid copying sources before compilation (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 18 Aug 2025 13:55:44 +0000 (15:55 +0200)
committerGitHub <noreply@github.com>
Mon, 18 Aug 2025 13:55:44 +0000 (13:55 +0000)
gh-123085: _compile_importlib: Avoid copying sources before compilation (GH-124131)
(cherry picked from commit 42c8b0556c02d29e32f4c7c95e7128a343716250)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Lib/test/test_importlib/resources/test_files.py

index f903d3bba85ebc9eafcb64a9052f7c4ca2d4256c..db8a4e62a32dc690c76008da89f1c3bfd2bf8ddb 100644 (file)
@@ -154,18 +154,17 @@ class ImplicitContextFiles:
     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):