Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 208
Nikita Avatar asked Jan 25 '16 13:01

Nikita


People also ask

What does setuptools setup do?

setuptools allows you to install a package without copying any files to your interpreter directory (e.g. the site-packages directory). This allows you to modify your source code and have the changes take effect without you having to rebuild and reinstall.

What is the purpose of setup py?

Use of Setup.py It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on. Secondly, it serves as the command line interface via which packaging commands may be executed.

What does pip install setup py do?

Python packages have a setup.py file that allows to easily install it while handling the dependencies. By default pip is trying to install from the Pypi: The Python Package Index (PyPI) is a repository of software for the Python programming language.

What is install requires in setup py?

install_requires is a setuptools setup.py keyword that should be used to specify what a project minimally needs to run correctly. When the project is installed by pip, this is the specification that is used to install its dependencies.


2 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.

like image 96
Martijn Pieters Avatar answered Sep 28 '22 05:09

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.

like image 31
Nikita Avatar answered Sep 28 '22 04:09

Nikita