[Distutils] Using Wheel with zipimport

Nick Coghlan ncoghlan at gmail.com
Wed Jan 29 08:32:14 CET 2014


All of those arguments are against *recommending* directly importing
from wheels. Yes, there are lots of problems with running directly
from a zip archive, which is why the fact that easy_install *actively
encourages* potentially inexperienced users to run things that way is
so problematic.

However, for people that are comfortable with the import system and
the limitations of direct zip imports, it's a very useful feature. I
wouldn't have accepted PEP 427 without the zipimport compatibility
that meant a developer *could* use it as a direct replacement for eggs
if they really wanted to.

Otherwise we'd have to define a whole new format for something that
can be adequately handled by a wheel that meets certain restrictions,
and that would be pointless (we already have too many formats, and we
wanted the wheel format to offer a strict superset of the egg format's
capabilities).

I clarified PEP 427 specifically because Armin Ronacher's wheel
article showed that he was unaware of this *deliberately included*
feature of the wheel format. People are free not to like it - the
default tools deliberately make it less convenient to run things that
way, and that's as it should be. However, it's not a super-secret
capability only to be used by us to implement things like ensurepip -
it's a defined capability of the format that if your software is
capable of running correctly from a zip archive in the first place,
then that archive can be also be a valid wheel file.

Running directly from a wheel is a power tool - that's a reason to put
"handle with care" warnings on it, not to refuse to support a feature
that was deliberately designed into the format. You can do a lot more
damage with a badly written meta-importer, yet we have no intention of
deprecating that capability either. Even *.pth files have turned out
to have a valid use case for sharing packages between virtual
environments.

We have lots of features like that elsewhere in Python - when people
ask about metaclasses, the first reaction is "You probably don't want
to use them". However, sometimes developers *do* need them, and that's
why the feature exists. Most of the time developers won't want to make
use of the zipimport compatibility of wheel files, either, but
advanced use cases like ensurepip are exactly why the capability
exists.

I can make the new note in the PEP more explicit that while this is a
supported use case that ensures the feature set provided by wheels is
a strict superset of that provided by eggs, that's not the same thing
as *recommending* that wheels be used that way.

Cheers,
Nick.


More information about the Distutils-SIG mailing list