Retrieve a finder for the given path item The returned finder is cached in sys.path_importer_cache if it was newly created by a path hook. The cache (or part of it) can be cleared manually if a rescan of sys.path_hooks is necessary.
(path_item)
| 208 | |
| 209 | |
| 210 | def get_importer(path_item): |
| 211 | """Retrieve a finder for the given path item |
| 212 | |
| 213 | The returned finder is cached in sys.path_importer_cache |
| 214 | if it was newly created by a path hook. |
| 215 | |
| 216 | The cache (or part of it) can be cleared manually if a |
| 217 | rescan of sys.path_hooks is necessary. |
| 218 | """ |
| 219 | path_item = os.fsdecode(path_item) |
| 220 | try: |
| 221 | importer = sys.path_importer_cache[path_item] |
| 222 | except KeyError: |
| 223 | for path_hook in sys.path_hooks: |
| 224 | try: |
| 225 | importer = path_hook(path_item) |
| 226 | sys.path_importer_cache.setdefault(path_item, importer) |
| 227 | break |
| 228 | except ImportError: |
| 229 | pass |
| 230 | else: |
| 231 | importer = None |
| 232 | return importer |
| 233 | |
| 234 | |
| 235 | def iter_importers(fullname=""): |
searching dependent graphs…