question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setuptools could respect python_requires

See original GitHub issue

Example: setup.py

from setuptools import setup

setup(
    name="my package",
    py_modules=["mypackage"],
    python_requires=">=3.4",
)

Example steps to reproduce:

$ python2 setup.py install 
... 
Installed .../lib/python2.7/site-packages/my_package-0.0.0-py2.7.egg
Processing dependencies for my-package==0.0.0
Finished processing dependencies for my-package==0.0.0

Expected: Command fails with an error explaining that the Python version isn’t supported.


Some packages workaround this by adding the following to the top of their setup.py:

if sys.version_info < (3, 4):
    raise Exception(...)

Rather than relying on each package to implement this, it could be handled once by setuptools.

An important use case, after porting a package to Python-3-only, one may mistakenly do:

$ python setup.py bdist_wheel 

On a system where python is Python 2 (most Linux systems), this produces a Python 2 wheel instead of a Python 3 wheel. This is clearly a mistake by the user, but if setuptools were to bail early, the mistake wouldn’t make it to PyPI.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nicoddemuscommented, Feb 12, 2019

Fair enough, thanks @pganssle! I think deprecating it would be a good start so people can move to more friendly and stable setups with tox. 👍

1reaction
pgansslecommented, Jan 9, 2019

This has some problems, which are essentially the same problems that invoking setup.py directly has, namely that in order to respect python_requires, setup() needs to run successfully, at least to the point where it parses the python version requirement. This means that anyone counting on setup.py only being run in Python 3 may have arbitrary failures.

Another issue is that python_requires is really intended to apply to the installed version of the package. It’s entirely plausible to build a Python 3-only package with Python 2 and vice versa, it’s just kinda rarely done. It’s not a big deal, but given the other problems with this approach, I’m not sure it makes sense to conflate the two pieces of metadata.

It would make sense if this information were stored in pyproject.toml, since it is meta-information about the build system itself. We can either lobby to add that to the pyproject.toml build-system spec or possibly just add a setuptools-specific configuration option to pyproject.toml when we resolve #1515.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent package from being installed on old Python versions
In your setup.py file, pass setup() a python_requires argument that ... python_requires argument to be processed; earlier versions will just ...
Read more >
Why you shouldn't invoke setup.py directly - Paul Ganssle
When you ran setup.py, setuptools would globally install whatever was in setup_requires before actually attempting to build your package.
Read more >
Dependencies Management in Setuptools
There are three types of dependency styles offered by setuptools: 1) build system requirement, 2) required dependency and 3) optional dependency.
Read more >
setup.py vs setup.cfg in Python - Towards Data Science
Discussing about setuptools and the difference between setup.py, setup.cfg ... respect to the purpose of requirements.txt and setuptools you can read one of ......
Read more >
Packaging and Python 2 - Discussions on Python.org
Concerning setuptools, I think a deprecation notice of a few months would have ... I guess pip could potentially be taught to respect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found