0

I just want to know if this is possible. For example, let's say if I want to build a pip package only for Linux or build a pip package for Windows and Mac but exclude Linux, is it possible to do that? Or do all pip packages become available for all 3 platforms (Windows, Mac, and Linux) when they get released?

Another example, let's say if Stripe wanted to release its Python SDK and make it Mac-only for Python users through pip, would that be possible?

I definitely would appreciate all answers as I am curious to know whether this is possible! I just want to know if this is possible or not. Thank you to those who do respond.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
Jazil Zaim
  • 335
  • 1
  • 3
  • 10

1 Answers1

1

You have to consider both sdist and wheel distributions.

For sdist there is not much you can do, they are multi platforms period. You can add safe-guards in setup.py, so that running it fails on some platforms, but that is far from elegant. The best practice is to document clearly that your project is only for specific platforms via the "trove classifiers", and also for example via your long_description and/or README.

For wheel, you can make it so that you only build platform-specific wheels, that's one of the things wheels are good at:

But best practices recommend you to publish the sdist as well in any case, so on other platforms the installer will fall-back to the sdist.

So to sum it up, you can build platform specific wheels but not platform-specific sdist. Document your project correctly (with trove classifiers) to declare which platforms are supported.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • Thank you for your answer! So basically I can't limit the source distribution (through sdist) but I can limit people from installing the Python packages through pip? Hopefully, I read that correctly, my apologies if I didn't. Also does it have to be only platform-specific code that I can restrict? Or can it also be plain Python code that a developer can restrict to certain platforms from installation as well? – Jazil Zaim Apr 11 '21 at 18:48
  • When you call pip to install `Thing`, first _pip_ will try to find a wheel of Thing that is compatible with the current environment (where pip is running), if pip does not find a good wheel candidate then it tries to find the sdist of Thing. The difference is that wheels can be platform specific. Thing could have wheels for windows and wheels for Linux for example. And if you are on Mac then there is no Mac wheel and pip will fall back to the _sdist_. And an sdist is never platform specific. For example: https://pypi.org/project/cryptography/#files – sinoroc Apr 11 '21 at 18:59