Skip to content

Commit 42c8b05

Browse files
encukoujaraco
andauthored
gh-123085: _compile_importlib: Avoid copying sources before compilation (GH-124131)
Co-authored-by: Jason R. Coombs <[email protected]>
1 parent 8a284e1 commit 42c8b05

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Lib/test/test_importlib/resources/test_files.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,17 @@ def test_implicit_files_submodule(self):
134134
def _compile_importlib(self):
135135
"""
136136
Make a compiled-only copy of the importlib resources package.
137+
138+
Currently only code is copied, as importlib resources doesn't itself
139+
have any resources.
137140
"""
138141
bin_site = self.fixtures.enter_context(os_helper.temp_dir())
139142
c_resources = pathlib.Path(bin_site, 'c_resources')
140143
sources = pathlib.Path(resources.__file__).parent
141-
shutil.copytree(sources, c_resources, ignore=lambda *_: ['__pycache__'])
142-
143-
for dirpath, _, filenames in os.walk(c_resources):
144-
for filename in filenames:
145-
source_path = pathlib.Path(dirpath) / filename
146-
cfile = source_path.with_suffix('.pyc')
147-
py_compile.compile(source_path, cfile)
148-
pathlib.Path.unlink(source_path)
144+
145+
for source_path in sources.glob('**/*.py'):
146+
c_path = c_resources.joinpath(source_path.relative_to(sources)).with_suffix('.pyc')
147+
py_compile.compile(source_path, c_path)
149148
self.fixtures.enter_context(import_helper.DirsOnSysPath(bin_site))
150149

151150
def test_implicit_files_with_compiled_importlib(self):

0 commit comments

Comments
 (0)