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='')
| 108 | |
| 109 | |
| 110 | def iter_modules(path=None, prefix=''): |
| 111 | """Yields ModuleInfo for all submodules on path, |
| 112 | or, if path is None, all top-level modules on sys.path. |
| 113 | |
| 114 | 'path' should be either None or a list of paths to look for |
| 115 | modules in. |
| 116 | |
| 117 | 'prefix' is a string to output on the front of every module name |
| 118 | on output. |
| 119 | """ |
| 120 | if path is None: |
| 121 | importers = iter_importers() |
| 122 | elif isinstance(path, str): |
| 123 | raise ValueError("path must be None or list of paths to look for " |
| 124 | "modules in") |
| 125 | else: |
| 126 | importers = map(get_importer, path) |
| 127 | |
| 128 | yielded = {} |
| 129 | for i in importers: |
| 130 | for name, ispkg in iter_importer_modules(i, prefix): |
| 131 | if name not in yielded: |
| 132 | yielded[name] = 1 |
| 133 | yield ModuleInfo(i, name, ispkg) |
| 134 | |
| 135 | |
| 136 | @simplegeneric |
no test coverage detected