packaging icon indicating copy to clipboard operation
packaging copied to clipboard

Reject supplied python_version attribute if it does not follow X or X.Y pattern

Open tvalentyn opened this issue 4 years ago • 0 comments

Context: https://github.com/pypa/pip/issues/8419.

When major.minor.patch versions are passed to python_version requirements specification (see https://www.python.org/dev/peps/pep-0508/), pip behavior is not intuitive:

docker -- run -it  --entrypoint /bin/bash python:3.5-slim-stretch
root@bcd3693fbfa1:/# python --version
Python 3.5.9

# installation does not happen even though  3.5.9 > 3.5.3
root@2108678766fc:/# pip install 'typing; python_version > "3.5.3"'                       
Ignoring typing: markers 'python_version > "3.5.3"' don't match your environment 

# installation happens even though  3.5.9 > 3.5.3
root@bcd3693fbfa1:/#  pip install 'typing; python_version < "3.5.3"'                        
Collecting typing
  Downloading typing-3.7.4.1-py3-none-any.whl (25 kB)
Installing collected packages: typing
Successfully installed typing-3.7.4.1

Correct usage seems for this scenario would be for user to pass python_full_version instead of python_version.

However, from a usability point of view, it would be better if pip alerted the user about incorrect usage of python_version rather than proceeding with behavior that does the opposite than a user's intent.

The investigation in https://github.com/pypa/pip/issues/8419 suggested that packaging would be a better place to implement the validation logic for python_version.

tvalentyn avatar Jun 10 '20 00:06 tvalentyn