Python packaging. Specify python version requirements after multiple releases

Viewed 236

I Have a package published on pypi and versioned as 3.0.0.

setup.py has never mentioned python_requires directive.

In release 2.5.0 there was a change which made package to be incompatible with python 2, which went unnoticed, until now.

Since 2.5.0 there were a plenty of releases of a package published on pypi.

Now, if I want to install the package using python2 - pip will install the latest release 3.0.0 which won't work.

I need pip to install version 2.4.0 - which has no compatibility issues. But how exactly can I accomplish that? (without prior knowledge of pip install package==2.4.0 - something like using pip's backtracking mechanism)

If I specify the directive python_requires=">=3.6" in release 3.1.0 pip will backtrack to release 3.0.0 installing package which won't work.

I can think of:

  1. cx_Oracle way. Raising exception in setup.py if minimal version does not match required for installation and specifying how to install correct one.

  2. Create 2 new releases. One, which is essentialy 2.4.0 versioned as 3.1.0 with python_requires=">=2.7,<3.6" and one which is 3.0.0 versioned as 3.1.1 with python_requires=">=3.6"

Is there a better way?

1 Answers

There is a relatively new feature on PyPI: you could "yank" the release(s) which are incompatible with Python 2 but not correctly specifying that in the metadata.

A yanked release is a release that is always ignored by an installer, unless it is the only release that matches a version specifier (using either == or ===).

See PEP 592 -- Adding "Yank" Support to the Simple API for more information. In fact, what you've described is the main scenario described in the motivation section of the PEP.

Related