Find the loader or namespace_path for this module/package name.
(cls, fullname, path, target=None)
| 1254 | |
| 1255 | @classmethod |
| 1256 | def _get_spec(cls, fullname, path, target=None): |
| 1257 | """Find the loader or namespace_path for this module/package name.""" |
| 1258 | # If this ends up being a namespace package, namespace_path is |
| 1259 | # the list of paths that will become its __path__ |
| 1260 | namespace_path = [] |
| 1261 | for entry in path: |
| 1262 | if not isinstance(entry, str): |
| 1263 | continue |
| 1264 | finder = cls._path_importer_cache(entry) |
| 1265 | if finder is not None: |
| 1266 | spec = finder.find_spec(fullname, target) |
| 1267 | if spec is None: |
| 1268 | continue |
| 1269 | if spec.loader is not None: |
| 1270 | return spec |
| 1271 | portions = spec.submodule_search_locations |
| 1272 | if portions is None: |
| 1273 | raise ImportError('spec missing loader') |
| 1274 | # This is possibly part of a namespace package. |
| 1275 | # Remember these path entries (if any) for when we |
| 1276 | # create a namespace package, and continue iterating |
| 1277 | # on path. |
| 1278 | namespace_path.extend(portions) |
| 1279 | else: |
| 1280 | spec = _bootstrap.ModuleSpec(fullname, None) |
| 1281 | spec.submodule_search_locations = namespace_path |
| 1282 | return spec |
| 1283 | |
| 1284 | @classmethod |
| 1285 | def find_spec(cls, fullname, path=None, target=None): |
no test coverage detected