Skip to content

Infer Python version from .python-version file when no backend is set#1802

Closed
Copilot wants to merge 1 commit into
copilot/consider-python-version-inferencefrom
copilot/sub-pr-1790
Closed

Infer Python version from .python-version file when no backend is set#1802
Copilot wants to merge 1 commit into
copilot/consider-python-version-inferencefrom
copilot/sub-pr-1790

Conversation

Copilot AI commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

When no package manager backend is active and requires-python is absent or yields no matches, usethis was unconditionally falling back to the running interpreter version. This ignores projects that pin their Python version via a .python-version file.

Changes

  • PythonVersion.from_python_version_file(path) — new classmethod on PythonVersion that reads and parses a .python-version file, raising FileNotFoundError or PythonVersionParseError on failure.
  • _get_current_python_version() — new private helper in environ/python.py that prefers .python-version (project root) and falls back to the running interpreter only when the file is absent or unparseable.
  • get_supported_minor_python_versions() — all three PythonVersion.from_interpreter() call sites replaced with _get_current_python_version(), covering the no-requires-python, empty-match, and out-of-bounds warning paths. Warning message updated from "Current Python interpreter" to "Current Python version" to reflect the broader source.
  • Step-down rule fix_get_current_python_version is placed above its caller per the project's step-down convention (follow-up commit).

Copilot AI changed the title [WIP] [WIP] Address feedback on inferring Python version with .python-version file Infer Python version from .python-version file when no backend is set Apr 4, 2026
Copilot AI requested a review from nathanjmcdougall April 4, 2026 00:59
@nathanjmcdougall

Copy link
Copy Markdown
Collaborator

Empty

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.

2 participants