Skip to content

Commit cade8d2

Browse files
committed
_compile_importlib: Avoid copying sources before compilation
1 parent aba42c0 commit cade8d2

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Lib/test/test_importlib/resources/test_files.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,21 @@ def _compile_importlib(self):
138138
bin_site = self.fixtures.enter_context(os_helper.temp_dir())
139139
c_resources = pathlib.Path(bin_site, 'c_resources')
140140
sources = pathlib.Path(resources.__file__).parent
141-
shutil.copytree(sources, c_resources, ignore=lambda *_: ['__pycache__'])
142141

143-
for dirpath, _, filenames in os.walk(c_resources):
142+
for dirpath, dirnames, filenames in os.walk(sources):
143+
try:
144+
dirnames.remove('__pycache__')
145+
except ValueError:
146+
pass
147+
source_dir_path = pathlib.Path(dirpath)
148+
dir_relpath = pathlib.Path(source_dir_path).relative_to(sources)
149+
c_dir_path = c_resources.joinpath(dir_relpath)
144150
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)
151+
if filename.endswith('.py'):
152+
source_path = source_dir_path / filename
153+
cfile = c_dir_path.joinpath(filename).with_suffix('.pyc')
154+
py_compile.compile(source_path, cfile)
155+
print(source_path, cfile)
149156
self.fixtures.enter_context(import_helper.DirsOnSysPath(bin_site))
150157

151158
def test_implicit_files_with_compiled_importlib(self):

0 commit comments

Comments
 (0)