Yields ModuleInfo for all submodules on path, or, if path is None, all top-level modules on sys.path. 'path' should be either None or a list of paths to look for modules in. 'prefix' is a string to output on the front of every module name on output.
(path=None, prefix='')
| 92 | |
| 93 | |
| 94 | def iter_modules(path=None, prefix=''): |
| 95 | """Yields ModuleInfo for all submodules on path, |
| 96 | or, if path is None, all top-level modules on sys.path. |
| 97 | |
| 98 | 'path' should be either None or a list of paths to look for |
| 99 | modules in. |
| 100 | |
| 101 | 'prefix' is a string to output on the front of every module name |
| 102 | on output. |
| 103 | """ |
| 104 | if path is None: |
| 105 | importers = iter_importers() |
| 106 | elif isinstance(path, str): |
| 107 | raise ValueError("path must be None or list of paths to look for " |
| 108 | "modules in") |
| 109 | else: |
| 110 | importers = map(get_importer, path) |
| 111 | |
| 112 | yielded = {} |
| 113 | for i in importers: |
| 114 | for name, ispkg in iter_importer_modules(i, prefix): |
| 115 | if name not in yielded: |
| 116 | yielded[name] = 1 |
| 117 | yield ModuleInfo(i, name, ispkg) |
| 118 | |
| 119 | |
| 120 | @simplegeneric |
no test coverage detected
searching dependent graphs…