Skip to content

Commit cc5d9cb

Browse files
encukoujaraco
andcommitted
gh-123085: _compile_importlib: Avoid copying sources before compilation (GH-124131)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
1 parent 313bed2 commit cc5d9cb

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

importlib_resources/tests/test_files.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,17 @@ def test_implicit_files_submodule(self):
154154
def _compile_importlib(self):
155155
"""
156156
Make a compiled-only copy of the importlib resources package.
157+
158+
Currently only code is copied, as importlib resources doesn't itself
159+
have any resources.
157160
"""
158161
bin_site = self.fixtures.enter_context(os_helper.temp_dir())
159162
c_resources = pathlib.Path(bin_site, 'c_resources')
160163
sources = pathlib.Path(resources.__file__).parent
161-
shutil.copytree(sources, c_resources, ignore=lambda *_: ['__pycache__'])
162-
163-
for dirpath, _, filenames in os.walk(c_resources):
164-
for filename in filenames:
165-
source_path = pathlib.Path(dirpath) / filename
166-
cfile = source_path.with_suffix('.pyc')
167-
py_compile.compile(source_path, cfile)
168-
pathlib.Path.unlink(source_path)
164+
165+
for source_path in sources.glob('**/*.py'):
166+
c_path = c_resources.joinpath(source_path.relative_to(sources)).with_suffix('.pyc')
167+
py_compile.compile(source_path, c_path)
169168
self.fixtures.enter_context(import_helper.DirsOnSysPath(bin_site))
170169

171170
def test_implicit_files_with_compiled_importlib(self):

0 commit comments

Comments
 (0)