[Python-Dev] Writing importers and path hooks

Brett Cannon brett at python.org
Thu Mar 28 14:42:08 CET 2013


On Wed, Mar 27, 2013 at 6:59 PM, Paul Moore <p.f.moore at gmail.com> wrote:

> On 27 March 2013 21:19, Bradley M. Froehle <brad.froehle at gmail.com> wrote:
> > I implemented just such a path hook ---- zipimporter plus the magic
> required
> > for C extensions --- as a challenge to myself to learn more about the
> Python
> > import mechanisms.
> >
> > See https://github.com/bfroehle/pydzipimport.
>
> Apologies for hijacking the thread, but it's interesting that you
> implemented your hook like this. I notice that you didn't use any of
> the importlib functionality in doing so. Was there a particular
> reason? I ask because a few days ago, I was writing a very similar
> importer, as I wanted to try a proof of concept importer based on the
> new importlib stuff (which is intended to make writing custom
> importers easier), and I really struggled to get something working.
>

Struggling how? With the finder? The loader? What exactly were you trying
to accomplish and how were you deviating from the standard import system?


>
> It seems to me that the importlib documentation doesn't help much for
> people trying to import path hooks.


There is a bug to clarify the docs to have more geared towards writing new
importers instead of just documenting what's available:
http://bugs.python.org/issue15867


> But it might be just me. Does
> anyone have an example of a simple importlib-based finder/loader?


Define simple. =) I would argue importlib itself is easy enough to read.


> That
> would be a huge help for me. In return for any pointers, I'll look at
> putting together a doc patch to clarify how to use importlib to build
> your own path hooks :-)
>

Do you specifically mean the path hook aspect or the whole package of hook,
finder, and loader?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130328/61590229/attachment.html>


More information about the Python-Dev mailing list