MCPcopy Create free account
hub / github.com/catboost/catboost / iter_modules

Method iter_modules

library/python/runtime_py3/__res.py:588–612  ·  view source on GitHub ↗
(self, package_prefix, prefix)

Source from the content-addressed store, hash-verified

586 raise ImportError(fullname)
587
588 def iter_modules(self, package_prefix, prefix):
589 paths = self._cache_module_path(package_prefix.rstrip('.'))
590 if paths is not None:
591 # Note: it's ok to yield duplicates because pkgutil discards them
592
593 # Yield from cache
594 import re
595 rx = re.compile(re.escape(package_prefix) + r'([^.]+)$')
596 # Save result to temporary list to prevent 'RuntimeError: dictionary changed size during iteration'
597 found = []
598 for mod, path in self.module_path_cache.items():
599 if path is not None:
600 m = rx.match(mod)
601 if m:
602 found.append((prefix + m.group(1), self.is_package(mod)))
603 yield from found
604
605 # Yield from file system
606 for path in paths:
607 abs_path = _path_join(self.source_root, path)
608 for dir_item in _os.listdir(abs_path):
609 if self._path_is_simple_dir(_path_join(abs_path, dir_item)):
610 yield prefix + dir_item, True
611 elif dir_item.endswith(self.PY_EXT) and _path_isfile(_path_join(abs_path, dir_item)):
612 yield prefix + dir_item[:-len(self.PY_EXT)], False
613
614 def _isdir(self, path):
615 """ Unlike _path_isdir() this function don't follow symlink """

Callers

nothing calls this directly

Calls 8

_cache_module_pathMethod · 0.95
is_packageMethod · 0.95
_path_is_simple_dirMethod · 0.95
lenFunction · 0.85
escapeMethod · 0.80
groupMethod · 0.80
matchMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected