[Distutils] Efficiently supporting multiple platforms in distribution packages

Paul Sokolovsky pmiscml at gmail.com
Mon Oct 27 16:15:12 CET 2014


Hello,

I just saw another topic posted,
https://mail.python.org/pipermail/distutils-sig/2014-October/025140.html ,
which raises question similar to which I had in mind for some time. To
not hijack that thread, I open a new one, but comment to a message from
that thread,
https://mail.python.org/pipermail/distutils-sig/2014-October/025142.html

So, my case: support different platforms in one distribution package.
To give more concrete example, let it be some module implemented using
ctypes, with completely different implementation for Linux, MacOSX, and
Windows. I'd also like to avoid installing files unneeded for
particular platform (a usecase applies to MicroPython
http://micropython.org/ , where there can be simply not enough storage
space to install cruft).

On Mon, 27 Oct 2014 14:04:38 +0000
Paul Moore <p.f.moore at ...> wrote:

> For a source distribution, you could play clever games in setup.py to
> put the right file in place, with the right name. But that's messy and
> it means that if you distribute wheels (not that there's much point in
> doing so) you need separate wheels for 2.6-, 2.7 and 3.3+.

Ok, so are there guidelines, best practices or at least example(s) how
to do that? I pretty much would like to avoid inventing my own "clever
games" to achieve that.


> Alternatively, you could distribute all 3 files, as
> 
> dbf
> \
>   - __init__.py
>   - dbf_26.py
>   - dbf_27.py
>   - dbf_3.py
> 
> Then in __init__.py do
> 
> if sys.version_info[0] == 3:
>   from .dbf_3 import *
> elif sys.version_info[:2] == (2, 7):
>   from .dbf_27 import *
> else
>   from .dbf_26 import *

For our MicroPython case, we would like to avoid this due to
aforementioned reasons. We could probably post-process installation dir
after pip to remove unneeded files, but that sounds like hack - we'd
rather do it fully on distribution package level, and target to install
just a single source file per module, and avoid dispatcher like above
(again, for efficiency reasons).


There's also another issue - of supporting "cross-installs". Not all
MicroPython targets support running pip natively, so it instead runs on
a host computer, but would need be instructed to select source
variants for a particular target platform.


Any hints/pointers on how to achieve this - preferrably in "standard"
way - are appreciated!


-- 
Best regards,
 Paul                          mailto:pmiscml at gmail.com


More information about the Distutils-SIG mailing list