Skip to content

Commit

Permalink
_compile_importlib: Avoid copying sources before compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
encukou committed Sep 16, 2024
1 parent aba42c0 commit cade8d2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Lib/test/test_importlib/resources/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,21 @@ def _compile_importlib(self):
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 dirpath, dirnames, filenames in os.walk(sources):
try:
dirnames.remove('__pycache__')
except ValueError:
pass
source_dir_path = pathlib.Path(dirpath)
dir_relpath = pathlib.Path(source_dir_path).relative_to(sources)
c_dir_path = c_resources.joinpath(dir_relpath)
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)
if filename.endswith('.py'):
source_path = source_dir_path / filename
cfile = c_dir_path.joinpath(filename).with_suffix('.pyc')
py_compile.compile(source_path, cfile)
print(source_path, cfile)
self.fixtures.enter_context(import_helper.DirsOnSysPath(bin_site))

def test_implicit_files_with_compiled_importlib(self):
Expand Down

0 comments on commit cade8d2

Please sign in to comment.