[Distutils] Supporting arch specific eggs with a fat Python and setuptools

Phillip J. Eby pje at telecommunity.com
Tue Feb 7 14:43:05 CET 2006

At 11:47 PM 2/6/2006 -0800, Bob Ippolito wrote:
>This sort must be used only with eggs that are compatible
>with the current architecture -- which means either "fat" or
>_macosx_arch(os.uname()[4].replace(' ', '_')).  Also allowing
>_macosx_arch and universally allowing fat are going to require
>another patch to setuptools (that I have not yet written, because
>it's not the right thing to do until egg-sorting is right).
>         # a and b must only differ in platform specifics!
>         def cmp_platform_eggs(a, b):
>                 if a.arch == "fat" and b.arch == "fat":
>                         pass
>                 elif a.arch == "fat":
>                         return 1
>                 elif b.arch == "fat":
>                         return -1
>                 # lower version sorts higher
>                 return -cmp(a.macosx_version, b.macosx_version)
>This sort means that fat will always be preferred, and lower
>requirements sort higher.  This makes it easier for people who wish
>to redistribute self-contained applications to other users (a la
>py2app, py2exe, cx_Freeze), which is a very important use case for
>this platform.

The way I'd recommend implementing this is via a _platform_key() function 
that takes a platform string and converts it to something that sorts the 
way you want it to; higher values are preferred to lower values.  Note that 
pkg_resources sorts distributions by version and other precedence 
information first; platform is the very *last* thing considered in a 
sort.  It also can't be guaranteed that you'll be comparing your custom 
object with a common platform.  So please try to write the patch with these 
constraints in mind.  On the line that's currently line 1758 of 
pkg_resources.py, you'll see a reference to 'self.platform'; change that to 
'_platform_key(self.platform)' once you've got your precedence algorithm 
figured out.

Note also that self.platform can be None, so _platform_key should not 
assume its parameter is a string.

More information about the Distutils-SIG mailing list