<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 6, 2013 at 4:26 AM, Thomas Heller <span dir="ltr"><<a href="mailto:theller@ctypes.org" target="_blank">theller@ctypes.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have become a fan of the new python 3.3 importlib<br>
in the last few days.<br></blockquote><div><br></div><div style>Glad it's working out for you!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
It has allowed me to write a ModuleMapper which I put into<br>
sys.metapath (in sitecustomize.py, for Python 3.3).<br>
<br>
This mapper currently does rename modules like 'Queue' or '_winreg'<br>
to the Python3 modules 'queue' or 'winreg' without the need to change<br>
my 2.7 sourcecode (changing the sourcecode is required when using<br>
six.moves to write 2.x/3.x compatible code).<br>
<br>
The six.moves approach has another problem with freeze tools (py2exe<br>
for example):  ModuleFinder does not find the moved modules because<br>
it cannot track __import__().<br>
<br>
<br>
I have also started a new modulefinder which uses importlib to find<br>
modules; this was quite easy since I could copy a lot of code from<br>
importlib._bootstrap.  The great thing is that this new modulefinder<br>
is much better than the old one:  It finds modules in zipped eggs<br>
or other zip-archives which are on sys.path; also it finds the renamed<br>
modules correctly that my ModuleMapper has mapped.<br>
<br>
<br>
The only thing that I am missing is that it is a bit of guesswork to<br>
find out the type of the module that importlib.find_loader() has found.<br>
<br>
Previously imp.find_module returned a tuple containing the type of<br>
module found (like imp.PY_SOURCE), I have to poke around in some<br>
attributes of the result of importlib.find_loader() to guess the type.<br></blockquote><div><br></div><div style>You should be able to tell with an isinstance check on the returned loader and not have to look at any attributes (e.g. source will subclass SourceLoader, frozen will subclass FrozenImporter, etc.). If it continues to be an issue just let me know and we can see what we can do (this is obviously a niche need and so I would prefer not to change the loader API to explicitly accommodate this, but it can be done).</div>

</div></div></div>