Skip to content

Commit

Permalink
Merge pull request #917 from dbnicholson/iter_modules
Browse files Browse the repository at this point in the history
Ignore nonexistent paths in iter_modules
  • Loading branch information
mhsmith committed Aug 19, 2023
2 parents bac5548 + 43e441d commit 9f30387
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion product/runtime/src/main/python/java/android/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,13 @@ def find_module(self, mod_name):

# Called by pkgutil.iter_modules.
def iter_modules(self, prefix=""):
for filename in self.listdir(self.prefix):
try:
filenames = self.listdir(self.prefix)
except OSError:
# ignore unreadable directories like import does
filenames = []

for filename in filenames:
zip_path = join(self.prefix, filename)
if self.isdir(zip_path):
for sub_filename in self.listdir(zip_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,11 @@ def check_iter_modules(mod, expected):
[(mi.name, mi.ispkg) for mi in
pkgutil.walk_packages(murmurhash.__path__, "murmurhash.")])

# Check that a non-existent package returns an empty list.
for path in ("somemissingpackage", "some/missing/package"):
mod_infos = list(pkgutil.iter_modules([f"{murmurhash.__path__[0]}/{path}"]))
self.assertEqual([], mod_infos)

def test_pr_distributions(self):
import pkg_resources as pr
self.assertCountEqual(REQUIREMENTS, [dist.project_name for dist in pr.working_set])
Expand Down

0 comments on commit 9f30387

Please sign in to comment.