Find the loader or namespace_path for this module/package name.
(cls, fullname, path, target=None)
| 1232 | |
| 1233 | @classmethod |
| 1234 | def _get_spec(cls, fullname, path, target=None): |
| 1235 | """Find the loader or namespace_path for this module/package name.""" |
| 1236 | # If this ends up being a namespace package, namespace_path is |
| 1237 | # the list of paths that will become its __path__ |
| 1238 | namespace_path = [] |
| 1239 | for entry in path: |
| 1240 | if not isinstance(entry, str): |
| 1241 | continue |
| 1242 | finder = cls._path_importer_cache(entry) |
| 1243 | if finder is not None: |
| 1244 | spec = finder.find_spec(fullname, target) |
| 1245 | if spec is None: |
| 1246 | continue |
| 1247 | if spec.loader is not None: |
| 1248 | return spec |
| 1249 | portions = spec.submodule_search_locations |
| 1250 | if portions is None: |
| 1251 | raise ImportError('spec missing loader') |
| 1252 | # This is possibly part of a namespace package. |
| 1253 | # Remember these path entries (if any) for when we |
| 1254 | # create a namespace package, and continue iterating |
| 1255 | # on path. |
| 1256 | namespace_path.extend(portions) |
| 1257 | else: |
| 1258 | spec = _bootstrap.ModuleSpec(fullname, None) |
| 1259 | spec.submodule_search_locations = namespace_path |
| 1260 | return spec |
| 1261 | |
| 1262 | @classmethod |
| 1263 | def find_spec(cls, fullname, path=None, target=None): |
no test coverage detected