ipmcc
ipmcc

Reputation: 29916

How can I make a Python package that is platform-specific?

I have a Python package that can only meaningfully run on Linux. I've seen in the docs that there is a platforms key in the setup.py metadata, but as far as I can tell from poking around in the distutils source, this metadata isn't actually used for anything.

Next, I went and looked at PyObjC, a prominent OS X-only Python package. I observe that it populates the aforementioned platforms key in its setup.py. However, when I try to install PyObjC on Linux, the installation isn't prevented or blocked in any intentional way. The failure mode that ensues is pretty ungraceful: it errors out when platform.mac_ver() returns a value it doesn't expect. I tried manually fixing that problem, and distutils appeared to be going about its merry way collecting dependencies, etc. until eventually it failed looking for a platform specific file... Bottom line, distutils is not handling platform-specific packages in any reasonable way.

Ideally, I would expect the installation to fail with some message indicating that the package is not compatible with the current platform. I've noodled around a bit and the "best" thing I've been able to come up with involves subclassing the install and develop commands and handling a platform check manually there.

Is there a better way?

Upvotes: 4

Views: 389

Answers (1)

RobertB
RobertB

Reputation: 1929

I am probably oversimplifying, but at the top of your setup.py couldn't you just do something like:

import platform
distname,version,id = platform.linux_distribution()
if not distname:
   raise Exception('Aborting installation: Requires Linux')

Upvotes: 2

Related Questions