Use PythonVersion class to parse and compare Python versions - #1748
Merged
Conversation
PythonVersion class to parse and compare Python versions
Bill Schnurr (bschnurr)
previously approved these changes
Aug 31, 2026
Eduardo Villalpando Mello (edvilme)
requested a review
from Bill Schnurr (bschnurr)
August 31, 2026 16:33
Eduardo Villalpando Mello (edvilme)
requested review from
Rich Chiodo (rchiodo)
and
a lite review from Copilot
August 31, 2026 16:58
Copilot started reviewing on behalf of
Eduardo Villalpando Mello (edvilme)
August 31, 2026 16:59
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new PythonVersion utility to normalize and compare Python interpreter version strings (including PET-style *.final.0 formats), and adopts it in environment sorting / “latest” selection and inline-script requires-python matching to address incorrect default interpreter selection (Fixes #1743).
Changes:
- Added
PythonVersionclass for parsing, normalization, comparison, andrequires-pythonspecifier evaluation. - Updated environment selection utilities (
sortEnvironments,getLatest) to usePythonVersioncomparisons instead of direct PEP 440 comparisons. - Updated inline-script metadata version matching to use
PythonVersion, with new/expanded unit tests.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/common/pythonVersion.ts | Adds normalized Python version parsing/comparison and specifier matching. |
| src/managers/common/utils.ts | Switches sorting and latest-environment selection to use PythonVersion. |
| src/common/inlineScript/metadata.ts | Replaces release-segment logic with PythonVersion for requires-python matching. |
| src/test/common/pythonVersion.unit.test.ts | Adds unit coverage for version normalization/comparison/specifiers. |
| src/test/managers/common/utils.getLatest.unit.test.ts | Adds unit tests for updated latest-environment selection. |
| src/test/managers/common/utils.sortEnvironments.unit.test.ts | Adds unit tests for updated environment sorting behavior. |
| src/test/common/inlineScript/metadata.unit.test.ts | Extends tests to cover normalized interpreter version formats. |
Suppressed comments (2)
src/common/pythonVersion.ts:41
PythonVersioncurrently rejects PEP 440-style versions with a leadingvprefix (e.g.v3.12.4). Elsewhere in the repo, version parsing explicitly tolerates a leadingv, so this can cause version comparisons / specifier matching to fail unexpectedly.
constructor(version: string) {
const normalizedVersion = version.trim();
const match = PythonVersion.VERSION_PATTERN.exec(normalizedVersion);
if (!match) {
src/test/common/pythonVersion.unit.test.ts:41
- Add a test that wildcard specifiers with a leading
v(e.g.==v3.14.*) are accepted, sinceWILDCARD_PATTERNis being updated to allow it.
assert.strictEqual(version.satisfies('==3.*'), true);
assert.strictEqual(version.satisfies('==3.14.*'), true);
assert.strictEqual(version.satisfies('==3.14.0.*'), true);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Copilot started reviewing on behalf of
Eduardo Villalpando Mello (edvilme)
August 31, 2026 17:25
View session
Rich Chiodo (rchiodo)
previously approved these changes
Aug 31, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Rich Chiodo (rchiodo)
approved these changes
Sep 1, 2026
Eduardo Villalpando Mello (edvilme)
enabled auto-merge (squash)
September 1, 2026 16:45
Bill Schnurr (bschnurr)
approved these changes
Sep 1, 2026
Eduardo Villalpando Mello (edvilme)
merged commit Sep 1, 2026
7d70c65
into
main
123 of 124 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new
PythonVersionclass to provide robust, normalized parsing and comparison of Python version strings. The codebase is updated to use this new class in thegetLatestutility, replacing the previous PEP 440-based implementation. Comprehensive unit tests are also added for both the version normalization logic and the updated selection of the latest Python environment.Python version normalization and comparison:
PythonVersionclass insrc/common/pythonVersion.ts, which normalizes Python version strings, supports comparison, and handles various version formats and prerelease suffixes.Integration with environment selection:
getLatestinsrc/managers/common/utils.tsto usePythonVersionfor selecting the latest Python environment, improving reliability and correctness in version comparisons.Testing improvements:
PythonVersioninsrc/test/common/pythonVersion.unit.test.ts, covering normalization, comparison, error handling, and parsing of various version formats.getLatestinsrc/test/managers/common/utils.getLatest.unit.test.tsto verify correct selection among multiple Python environments, including handling of invalid and errored entries.Dependency updates:
src/managers/common/utils.tsto include the newPythonVersionclass.Fixes #1743