[Distutils] Limit package installation to a specific Python version

Nathaniel Smith njs at pobox.com
Fri Jan 20 17:56:47 EST 2017


On Fri, Jan 20, 2017 at 1:56 PM, Lele Gaifax <lele at metapensiero.it> wrote:
> Hi all,
>
> do installers like pip and conda consult trove classifiers, or more generally
> is there a way to "mark" a package published on PyPI as installable only in a
> Python 3 environment?
>
> An user proposed[1] to change the classifiers of a package to get that result,
> so I tried looking at pip and setuptools sources, but didn't find evidence of
> that. I see both use python_requires[2] in their setup that seem closer to the
> goal, but again, is that actually honored by pip and/or other installers?
>
> Thanks for any hint,
> ciao, lele.
>
> [1] https://github.com/python-rapidjson/python-rapidjson/pull/47
> [2] https://www.python.org/dev/peps/pep-0345/#requires-python

Neither pip nor conda do anything automatically with trove
classifiers. Conda uses its own metadata added when the conda package
is built; whoever runs your conda-build can probably figure something
out. Wheels have always had this metadata and pip has always honored
it. For sdists, historically there was no way to do this, but as of a
few months ago this was fixed and pip now *does* honor
python_requires, and PyPI has been updated to expose this information
so pip can see it before downloading the sdists:

    https://github.com/pypa/pip/pull/3846
    https://github.com/python/peps/pull/56
    https://github.com/pypa/pip/pull/3877

Since this is a pretty recent change, you probably want to put a
runtime check inside your setup.py for old Python versions, so if
someone uses an old version of pip then they will at least get a nice
explanation.

IPython's an example of a python-3-only project that uses this
belt-and-suspenders approach:

https://github.com/ipython/ipython/blob/f060158665189fd456e54a5a864080efe28b4fdf/setup.py#L29
https://github.com/ipython/ipython/blob/f060158665189fd456e54a5a864080efe28b4fdf/setup.py#L248

-n

-- 
Nathaniel J. Smith -- https://vorpus.org


More information about the Distutils-SIG mailing list