cpython: dc24ab548e2b (original) (raw)

Mercurial > cpython

changeset 100594:dc24ab548e2b

Issue #26252: Add an example on how to register a finder [#26252]

Brett Cannon brett@python.org
date Fri, 18 Mar 2016 11:54:22 -0700
parents 6fed752fd88e
children a2bf6d1e018e
files Doc/library/importlib.rst
diffstat 1 files changed, 32 insertions(+), 2 deletions(-)[+] [-] Doc/library/importlib.rst 34

line wrap: on

line diff

--- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -1335,7 +1335,7 @@ import, then you should use :func:`impor if spec is None: print("can't find the itertools module") else:

@@ -1359,11 +1359,41 @@ To import a Python source file directly,

by name later.

sys.modules[module_name] = module +For deep customizations of import, you typically want to implement an +:term:importer. This means managing both the :term:finder and :term:loader +side of things. For finders there are two flavours to choose from depending on +your needs: a :term:meta path finder or a :term:path entry finder. The +former is what you would put on :attr:sys.meta_path while the latter is what +you create using a :term:path entry hook on :attr:sys.path_hooks which works +with :attr:sys.path entries to potentially create a finder. This example will +show you how to register your own importers so that import will use them (for +creating an importer for yourself, read the documentation for the appropriate +classes defined within this package):: +

+