Skip to content

Commit

Permalink
gh-123085: _compile_importlib: Avoid copying sources before compilati…
Browse files Browse the repository at this point in the history
…on (GH-124131)

Co-authored-by: Jason R. Coombs <[email protected]>
  • Loading branch information
encukou and jaraco committed Sep 19, 2024
1 parent 313bed2 commit cc5d9cb
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions importlib_resources/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,17 @@ def test_implicit_files_submodule(self):
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):
Expand Down

0 comments on commit cc5d9cb

Please sign in to comment.