Skip to content

Clarify Python constraint incompatibility error#2335

Open
danialza wants to merge 1 commit into
pypa:masterfrom
danialza:fix-python-constraint-error
Open

Clarify Python constraint incompatibility error#2335
danialza wants to merge 1 commit into
pypa:masterfrom
danialza:fix-python-constraint-error

Conversation

@danialza

@danialza danialza commented Jul 5, 2026

Copy link
Copy Markdown

Fixes #2181

Summary

  • Report when a configured environment Python version is excluded by the project requires-python constraint instead of saying it cannot be located.
  • Preserve the existing cannot locate Python message for unknown or unavailable Python versions.
  • Add a CLI regression test and update the Hatch history.

Root cause

Compatibility checks use the same final fallback for a missing interpreter and for an interpreter that was intentionally rejected by requires-python, so the error message could point users in the wrong direction.

Checks

  • PATH="$PWD/.venv/bin:$PATH" .venv/bin/python -m pytest tests/cli/env/test_create.py::test_incompatible_python_constraint tests/cli/env/test_create.py::test_incompatible_single tests/cli/env/test_create.py::test_incompatible_matrix_full tests/cli/env/test_create.py::test_incompatible_matrix_partial tests/cli/run/test_run.py::test_incompatible_missing_python -q
  • .venv/bin/python -m ruff check src/hatch/env/virtual.py tests/cli/env/test_create.py
  • .venv/bin/python -m ruff format --check src/hatch/env/virtual.py tests/cli/env/test_create.py
  • .venv/bin/python -m mypy src/hatch/env/virtual.py
  • .venv/bin/python scripts/validate_history.py

@danialza danialza marked this pull request as ready for review July 5, 2026 02:40
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.

Misleading error message when requires-python doesn’t match environment Python

1 participant