pypa / pypa/packaging

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

Open
#314 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement packaging.version
Dominant language
Python
Stars
751
Forks
324
Avg merge
12h 58m
Merged PRs (30d)
3

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review packaging's handling of the python_version marker against the PEP 508 rules and the investigation in pypa/pip#8419. Add validation that rejects values outside the X or X.Y pattern and cover the rejection and valid cases with tests; the issue does not name specific files or existing tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.