Skip to content

Commit 8cd8fe9

Browse files
committed
Rely on pathlib.Path.glob for simplicity.
1 parent 211b436 commit 8cd8fe9

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

Lib/test/test_importlib/resources/test_files.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,9 @@ def _compile_importlib(self):
142142
c_resources = pathlib.Path(bin_site, 'c_resources')
143143
sources = pathlib.Path(resources.__file__).parent
144144

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

160150
def test_implicit_files_with_compiled_importlib(self):

0 commit comments

Comments
 (0)