flit icon indicating copy to clipboard operation
flit copied to clipboard

Question: specify platform compatibility

Open karrukola opened this issue 4 years ago • 1 comments

Hello, thanks for making this tool, first of all.

I am wondering whether there is a way to specify that the distribution package is not suitable for certain OSes. This would reflect in the platform tag as per PEP425. I could not grasp it from the documentation.

The rationale/use case I have for this question is the following example.

A project may use pexpect.spawn() that is not supported by Windows. Rather than identifying this problem at execution time it would be better to avoid the installation on Windows in the first place. My understanding is that, as a solution, the wheel should better not indicate any in the Platform Tag even though it is a pure Python project.

A couple of additional considerations:

  • pexpect is delivered for Windows, so the dependency would be installed and the failure identified at runtime
  • using an environment marker would prevent the installation of such dependency, but not of the whole package. I.e. dependencies = [ "pexpect; sys_platform != 'win32'", ]
  • Trove Classifiers are not used by installation tools such as pip, so that won't help as well

Am I missing anything? Please advise.

Thanks again.

karrukola avatar Oct 06 '21 14:10 karrukola

Hi! There's not really any good way to do this with Python packaging at the moment.

The wheel tags (PEP 425) are meant to label a specific pre-built package of your code, not the whole project. They're for things like C extension modules, where the code has to be built separately for each platform. So by default, if there's no compatible wheel, pip will fall back to fetching and installing from the sdist (.tar.gz package). And there's no way to mark an sdist as platform specific - except the Trove classifiers, which you already mentioned.

With setuptools, you can put a check in setup.py and error out on the wrong platform. This plus wheel tags can achieve the result you want, but it's kind of ugly. And it's possible to run setup.py on one platform to prepare packages for another platform.

If you think this is important, probably the place to start is the packaging section of the Python forum. The obvious thing might be for installers (pip) to respect platform trove classifiers, but there's a risk that breaks installing packages with incorrect metadata that have worked for years, so a new mechanism might be required.

takluyver avatar Oct 06 '21 14:10 takluyver

I'm going to close this issue - I think it's more a question about the packaging standards & ecosystems more broadly, rather than Flit by itself.

takluyver avatar Jan 28 '24 10:01 takluyver