What does the `platforms` argument to `setup()` in `setup.py` do?

Question:

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.

Asked By: Nikita

||

Answers:

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.

Answered By: Martijn Pieters

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.

Answered By: Nikita