When you mount a wheel, its absolute path name is added to
sys.path, allowing the Python code in it to be imported.
> Better: just put the wheel path to sys.path
sys.path.append('/tmp/simplejson-3.1.2-cp27-none-linux_x86_64.whl')
> and let a sys.path_hook entry do the job.
That's what the mount() actually does - adds the wheel to a registry that an
import hook uses. You also need a place to check that the wheel being mounted
is compatible with the Python doing the mounting - I'm not sure whether what
the import hook should do if e.g. there is a compatibility problem with the
wheel (e.g. is it clear that it should always raise an ImportError? Or ignore
the wheel - seems wrong? Or do something else?)
2013/3/27 Vinay Sajip <vinay...@yahoo.co.uk>Better: just put the wheel path to sys.path
When you mount a wheel, its absolute path name is added to
sys.path, allowing the Python code in it to be imported.sys.path.append('/tmp/simplejson-3.1.2-cp27-none-linux_x86_64.whl')and let a sys.path_hook entry do the job.Such a WheelImporter could even inherit from zipimporter, plus the magic required for C extensions.
Am 27.03.2013 20:38, schrieb Vinay Sajip:The zip-file itself could support importing compiled extensions when it contains a python-wrapper module that unpacks the .so/.dll file somewhere, and finally calls imp.load_dynamic() to import it and replace itself.
This quote is here to stop GMane complaining that I'm top-posting. Ignore.
I've already posted this to distutils-sig, but thought that it might be of
interest to readers here as it relates to importing C extensions ...
zipimport is great, but there can be issues importing software that contains
C extensions. But the new wheel format (PEP 427) may give us a better way of
importing zip files containing C extensions. Since wheels are .zip files, they
can sometimes be used to provide functionality without needing to be installed.
But whereas .zip files contain no convention for indicating compatibility with
a particular Python, wheels do contain this compatibility information. Thus, it
is possible to check if a wheel can be directly imported from, and the wheel
support in distlib allows you to take advantage of this using the mount() and
unmount() methods. When you mount a wheel, its absolute path name is added to
sys.path, allowing the Python code in it to be imported. (A DistlibException is
raised if the wheel isn't compatible with the Python which calls the mount()
method.)