Skip to content

Accept a major-only python_version such as "3" - #6688

Merged
matteius merged 2 commits into
pypa:mainfrom
dchaudhari7177:fix/major-only-python-version
Jul 30, 2026
Merged

Accept a major-only python_version such as "3"#6688
matteius merged 2 commits into
pypa:mainfrom
dchaudhari7177:fix/major-only-python-version

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

Summary

Fixes #6687. python_version = "3" in the Pipfile [requires] section — which the docs list as valid — produced a spurious mismatch warning on install and a fatal DeployException under --deploy.

_python_version_matches_required branches on how many components the requirement has, but only distinguished "3 or more" from "everything else":

if len(required_ver_str.split(".")) >= 3:
    return actual == required            # full version, exact
else:
    return actual.major == required.major and actual.minor == required.minor

"3" has one component, so it took the second branch — and parse_version("3") fills in a zero minor, so the comparison became actual.minor == 0. Every 3.x interpreter except 3.0 was rejected:

parse_version("3") -> 3 | major 3 | minor 0
actual=3.13.14  required='3'  -> False

Change

Compare only the components actually given:

requirement compared
"3" major only
"3.13" major + minor
"3.13.1" exact

The PEP 440 specifier path (">=3.9", ">=3.9,<4") is untouched.

Tests

TestPythonVersionMatchesRequired already has a parametrized table, so the major-only cases go in alongside the existing #6514 substring-regression rows: 3.13.14/3.9.1/3.0.0/3.11 all satisfy "3", while 2.7.18 and 4.0.0 don't, plus 2.7.18 against "2" so the rule isn't special-cased to Python 3.

Reverting only pipenv/ fails exactly the new rows and nothing else:

FAILED ...test_version_match[3.13.14-3-True]
FAILED ...test_version_match[3.9.1-3-True]
FAILED ...test_version_match[3.11-3-True]
FAILED ...test_version_match[2.7.18-2-True]
4 failed, 22 passed

Verification

  • pytest tests/unit/test_utils.py -k PythonVersionMatchesRequired → 26 passed
  • pytest tests/unit/test_utils.py210 passed, 5 skipped (skips are POSIX-only path tests, I'm on Windows)
  • ruff check on both changed files → all checks passed
  • Added news/6687.bugfix.rst

One note: ruff format --check reports both changed files as needing reformatting, but that's pre-existing on a clean tree (verified by stashing), so I left it alone rather than mixing unrelated reformatting into this diff.

The Pipfile [requires] section documents "3" as a valid python_version,
but the version check compared the major AND minor components whenever
fewer than three were given. "3" parses to 3.0, so every 3.x
interpreter except 3.0 was reported as a mismatch, producing a spurious
warning on install and a fatal DeployException under --deploy.

Compare only the components actually given: major alone for "3", major
and minor for "3.13", and an exact match for a full "3.13.1". The
existing PEP 440 specifier path is untouched.

Closes pypa#6687

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect Python version compatibility checks when python_version in the Pipfile [requires] section is specified as a major-only version like "3", aligning behavior with documented support and preventing spurious mismatch warnings / DeployException failures under --deploy.

Changes:

  • Update _python_version_matches_required() to compare only the components explicitly provided ("3" → major-only, "3.13" → major+minor, "3.13.1" → exact).
  • Extend unit tests to cover major-only python_version requirements (including non-3 majors).
  • Add a news/ bugfix entry describing the regression and fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pipenv/utils/project.py Adjusts version-matching logic to handle major-only requirements correctly.
tests/unit/test_utils.py Adds regression tests validating major-only version matching behavior.
news/6687.bugfix.rst Documents the restored support and user-facing impact.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pipenv/utils/project.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@matteius
matteius merged commit 579de8f into pypa:main Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Major-only python_version triggers a version mismatch

4 participants