summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2024-09-18 12:14:34 (GMT)
committerGitHub <noreply@github.com>2024-09-18 12:14:34 (GMT)
commit42c8b0556c02d29e32f4c7c95e7128a343716250 (patch)
treec22f2dcdf8d85cda16cc6857dfb7dadb4d69c2d8
parent8a284e189673582e262744618f293f9901a32e49 (diff)
downloadcpython-42c8b0556c02d29e32f4c7c95e7128a343716250.zip
cpython-42c8b0556c02d29e32f4c7c95e7128a343716250.tar.gz
cpython-42c8b0556c02d29e32f4c7c95e7128a343716250.tar.bz2
gh-123085: _compile_importlib: Avoid copying sources before compilation (GH-124131)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
-rw-r--r--Lib/test/test_importlib/resources/test_files.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/Lib/test/test_importlib/resources/test_files.py b/Lib/test/test_importlib/resources/test_files.py
index 3cdbee3..933894d 100644
--- a/Lib/test/test_importlib/resources/test_files.py
+++ b/Lib/test/test_importlib/resources/test_files.py
@@ -134,18 +134,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):