Loop over the modules present below this entry or package on PYTHONPATH. For modules which are not packages, this will yield nothing. For packages and path entries, this will only yield modules one level down; i.e. if there is a package a.b.c, iterModules on a will
(self)
| 112 | """ |
| 113 | |
| 114 | def iterModules(self): |
| 115 | """ |
| 116 | Loop over the modules present below this entry or package on PYTHONPATH. |
| 117 | |
| 118 | For modules which are not packages, this will yield nothing. |
| 119 | |
| 120 | For packages and path entries, this will only yield modules one level |
| 121 | down; i.e. if there is a package a.b.c, iterModules on a will only |
| 122 | return a.b. If you want to descend deeply, use walkModules. |
| 123 | |
| 124 | @return: a generator which yields PythonModule instances that describe |
| 125 | modules which can be, or have been, imported. |
| 126 | """ |
| 127 | yielded = {} |
| 128 | if not self.filePath.exists(): |
| 129 | return |
| 130 | |
| 131 | for placeToLook in self._packagePaths(): |
| 132 | try: |
| 133 | children = sorted(placeToLook.children()) |
| 134 | except UnlistableError: |
| 135 | continue |
| 136 | |
| 137 | for potentialTopLevel in children: |
| 138 | ext = potentialTopLevel.splitext()[1] |
| 139 | potentialBasename = potentialTopLevel.basename()[: -len(ext)] |
| 140 | if ext in PYTHON_EXTENSIONS: |
| 141 | # TODO: this should be a little choosier about which path entry |
| 142 | # it selects first, and it should do all the .so checking and |
| 143 | # crud |
| 144 | if not _isPythonIdentifier(potentialBasename): |
| 145 | continue |
| 146 | modname = self._subModuleName(potentialBasename) |
| 147 | if modname.split(".")[-1] == "__init__": |
| 148 | # This marks the directory as a package so it can't be |
| 149 | # a module. |
| 150 | continue |
| 151 | if modname not in yielded: |
| 152 | yielded[modname] = True |
| 153 | pm = PythonModule(modname, potentialTopLevel, self._getEntry()) |
| 154 | assert pm != self |
| 155 | yield pm |
| 156 | else: |
| 157 | if ( |
| 158 | ext |
| 159 | or not _isPythonIdentifier(potentialBasename) |
| 160 | or not potentialTopLevel.isdir() |
| 161 | ): |
| 162 | continue |
| 163 | modname = self._subModuleName(potentialTopLevel.basename()) |
| 164 | for ext in PYTHON_EXTENSIONS: |
| 165 | initpy = potentialTopLevel.child("__init__" + ext) |
| 166 | if initpy.exists() and modname not in yielded: |
| 167 | yielded[modname] = True |
| 168 | pm = PythonModule(modname, initpy, self._getEntry()) |
| 169 | assert pm != self |
| 170 | yield pm |
| 171 | break |
no test coverage detected