32

Looking through several projects recently, I noticed some of them use platforms argument to setup() in setup.py, though with only one value of any, i.e.

#setup.py file in project's package folder 
...   
setup(
      ...,
      platforms=['any'],
      ...
)

OR

#setup.py file in project's package folder
...  
setup(
      ...,
      platforms='any',
      ...
)

From the name "platforms", I can make a guess about what this argument means, and it seems that the list variant is the right usage.

So I googled, looked through setuptools docs, but I failed to find any explanation to what are the possible values to platforms and what it does/affects in package exactly.

Please, explain or provide a link to explanation of what it does exactly and what values it accepts?

P.S. Also tried to provide different values to it in my OS independent package and see what changes, when creating wheels, but it seems it does nothing.

0 _
  • 10,524
  • 11
  • 77
  • 109
Nikita
  • 6,101
  • 2
  • 26
  • 44

2 Answers2

22

platforms is an argument the setuptools package inherits from distutils; see the Additional meta-data section in the distutils documentation:

Meta-Data: platforms
Description: a list of platforms
Value: list of strings

So, yes, using a list is the correct syntax.

The field just provides metadata; what platforms does the package target. Use this to communicate to tools or people about where you expect the package to be used.

There is no further specification for the contents of this list, it is unstructured and free-form. If you want to use something more structured, use the available Trove classifier strings in the classifiers field, where tags under Operating System, Environment and others let you more strictly define a platform.

Wheels do not use this field other than to include it in the metadata, just like other fields like author or license.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Thank you, I saw that, but except that it's a list of strings there's no more information on it on that link. Will pip consider this field when you try to install some package, say on linux, and `platforms` is set to `win32` or something? – Nikita Jan 25 '16 at 13:54
  • 1
    @Nikita: there is little more to say about it. There are no automated tools using this field. – Martijn Pieters Jan 25 '16 at 13:55
  • 3
    So basically it's outdated and has no real use? I mean, you can get intended platforms from `classifiers` if you have too. – Nikita Jan 25 '16 at 13:56
  • 1
    @Nikita: exactly; `classifiers` is far more structured and defined. – Martijn Pieters Jan 25 '16 at 14:00
  • I see, thank you! But let's see if anyone will have something to add. – Nikita Jan 25 '16 at 14:02
  • 3
    Sure, feel free. If it helps anything, I've been building and releasing Python projects for 15+ years now, I'm pretty confident there is no other answer. :-) – Martijn Pieters Jan 25 '16 at 14:03
  • I found an actual "use" of the `platforms` attribute. When I build my own extension with `bdist_wheel` and install it with `pip install`, I see the platforms listed in the _.dist-info/METADATA_ file. I'm not saying this is a significant use or affects anything else, just that it's not ignored, and is forwarded to the installation as metadata. Not specifying it in _setup.py_ causes that file to say the platform is "Unknown". – Jim Apr 15 '22 at 22:21
  • @Jim: yes, which is what my answer already states. The metadata is copied across, but no _installer_ uses the data automatically to make any installation decisions. – Martijn Pieters Apr 16 '22 at 09:53
8

Just an update to provide more information for anyone interested.

I found an accurate description of platforms in a PEP.

So, "There's a PEP for that!":

PEP-0345 lists all possible arguments to setup() in setup.py, but it's a little old.

PEP-0426 and PEP-0459 are newer versions describing metadata for Python packages.

Nikita
  • 6,101
  • 2
  • 26
  • 44