[Distutils] Optional C extensions in packages

Phillip J. Eby pje at telecommunity.com
Thu Feb 1 19:03:53 CET 2007

At 07:11 AM 2/1/2007 -0500, Jim Fulton wrote:
>I like the goal, since most of our extensions are in this category,
>however, I have a feeling that this use case might be better served
>by packaging the extensions as separate distributions.

True, but without automation, it's more work for the package author to "do 
the right thing".  If your extension is in a package, you have to make it a 
namespace package.  You have to create another setup.py and directory 
structure, and manage another set of releases.  This is a lot more work 
than just marking the extension as "optional".

>Once concern I have is that I think I'd want an egg with the extensions
>and the egg without the extensions to have different names, and perhaps
>different requirements.  Of course, the names would be different
>because an egg with a C extension would be platform dependent and an
>egg without would be platform independent.  What if both a
>platform-independent egg and a platform-dependent egg were available?
>Which would take precedence? I think they have the same precedence now.
>I think I'd be +1 if platform-dependent eggs were prefered over
>platform-independent ones.

...of the same version?  That's easy enough to do by changing the 
Distribution.hashcmp property to put the 'platform' part earlier in the 
comparison.  If they're different versions, however, it's a whole 'nother 
kettle of fish.

The solution I was thinking of, however, has the additional benefit of 
working right now.  If you're generating eggs for a package with optional 
extensions, you would simply *not* generate a cross-platform egg, but 
instead just ship an sdist tarball, plus platform-specific eggs for the 
platforms you care about.  That way, anybody on an unsupported platform 
will end up building a local egg from the source, and either producing the 
extensions or skipping them locally.  (And if you don't have access to a 
compiler, it seems unlikely that you will be then *distributing* the eggs 
you produced.)

Notice that this setup is a natural side-effect of the way most people 
would produce and upload packages to the Cheeseshop anyway - you would have 
to make an intentional effort to suppress extension-building and upload a 
cross-platform egg; otherwise you will just end up with a source 
distribution and a platform-specific egg, which then works as intended.

More information about the Distutils-SIG mailing list