Skip to content

Validate Python version when using --system flag#6453

Merged
matteius merged 1 commit intomainfrom
fix/system-python-version-check
Dec 9, 2025
Merged

Validate Python version when using --system flag#6453
matteius merged 1 commit intomainfrom
fix/system-python-version-check

Conversation

@matteius
Copy link
Copy Markdown
Member

@matteius matteius commented Dec 9, 2025

Summary

Fixes #6403

Previously, pipenv install --system --deploy would silently proceed even if the system Python version didn't match the python_version specified in Pipfile/Pipfile.lock. This was a significant gap in the --deploy safety checks.

The Problem

The Python version validation code was only executed inside the if not system_or_exists: block, which means it was skipped entirely when using --system. This allowed installations to proceed with an incompatible Python version without any warning or error.

The Fix

This PR moves the Python version check outside of the virtualenv creation block so it runs for both:

  • Standard virtualenv installations
  • --system installations

When --deploy is used with an incompatible Python version, a DeployException is now properly raised.

The fix also adjusts the warning message: the suggestion to use pipenv --rm is only shown for virtualenv installations (not --system).

Testing

Before this fix (using the Dockerfile from the issue):

FROM python:3.13-slim
# Pipfile requires python_version = "3.12"
RUN pipenv install --system --deploy
# ✓ Succeeds (should fail!)

After this fix:

RUN pipenv install --system --deploy
# ✗ Raises DeployException (expected behavior)

Checklist


Pull Request opened by Augment Code with guidance from the PR author

Fixes #6403

Previously, 'pipenv install --system --deploy' would silently proceed
even if the system Python version didn't match the python_version
specified in Pipfile/Pipfile.lock. This was because the version check
was only performed when creating a new virtualenv, not when using
--system.

This moves the Python version check outside of the virtualenv creation
block so it runs for both virtualenv and --system installations.
When --deploy is used with an incompatible Python version, a
DeployException is now properly raised.
@matteius matteius merged commit cbf1f68 into main Dec 9, 2025
19 of 20 checks passed
@matteius matteius deleted the fix/system-python-version-check branch December 9, 2025 21:08
matteius added a commit that referenced this pull request Mar 18, 2026
…check

Fixes #6514

The check introduced in #6453 used a substring 'not in' test to compare
the required Python version (from Pipfile [requires]) against the actual
Python version. This produces false-negatives (silently accepting an
incompatible interpreter) whenever the required version string happens to
be a substring of the actual version string.

Concrete example from the issue:

  required  = "3.11"     (python_version in Pipfile.lock)
  actual    = "3.13.11"  (system Python in the Docker image)

  "3.11" in "3.13.11"  →  True   ← wrong: they are NOT compatible
  ("3.11" matches characters 3-6 of "3.13.11")

This silently skipped the incompatibility warning/error, so
'pipenv install --deploy --system' succeeded when it should have aborted.

Fix: replace the substring check with proper semantic version comparison
via packaging.version.parse (already imported in the module):

  * When required_python_version has only two dot-separated components
    (i.e. python_version = "X.Y"), compare only the major and minor
    fields of the parsed versions.
  * When it has three or more components (python_full_version = "X.Y.Z"),
    require an exact match.

The comparison is extracted into a module-level helper function
_python_version_matches_required() to keep ensure_project() readable and
to allow direct unit testing.

Tests: 19 parametrised cases added in TestPythonVersionMatchesRequired,
covering the exact substring-trap from the issue, additional ambiguous
pairs ("3.9"/"3.9.10", "3.1"/"3.11.0", "3.11.1"/"3.11.10"), major-version
mismatches, python_full_version exact-match and mismatch cases, and
empty-string edge cases.
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.

Incompatible Python version silently ignored rather than erroring, when using --system

1 participant