Refactor Python version logic into a dedicated class#1216
Merged
nathanjmcdougall merged 1 commit intomainfrom Dec 23, 2025
Conversation
This helps reduce duplication and adds clarity around the source for the version inference. Also, the version of Ruff is bumped here to pass tests. Likewise, some GitHub API flakiness is now skipped for version monitoring tests
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors Python version handling by introducing a dedicated PythonVersion class to replace scattered version string manipulation logic. The key changes consolidate version parsing, formatting, and comparison into a single abstraction that handles standard versions (3.10.5) and pre-release versions (3.14.0a3) uniformly.
- Introduces
PythonVersiondataclass withfrom_string(),from_interpreter(), andto_short_string()methods - Replaces function-based version utilities (
get_python_version(),get_python_major_version(),extract_major_version()) with class-based API - Updates function names from "major" to "minor" terminology to reflect actual usage (e.g.,
get_supported_uv_major_python_versions()→get_supported_uv_minor_python_versions()) - Adds timeout handling for GitHub API flakiness in version monitoring tests
- Bumps Ruff version from v0.14.9 to v0.14.10
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/usethis/_integrations/python/version.py | Core refactor: replaces utility functions with PythonVersion class that handles parsing, formatting, and immutability |
| src/usethis/_integrations/backend/uv/python.py | Updates to use PythonVersion class; function renamed to reflect minor version handling |
| src/usethis/_integrations/environ/python.py | Updates to use PythonVersion class and renamed function |
| src/usethis/_integrations/sonarqube/config.py | Replaces custom version parsing with PythonVersion class methods |
| src/usethis/_tool/impl/pytest.py | Updates to use PythonVersion class for Bitbucket step generation |
| src/usethis/_integrations/ci/bitbucket/steps.py | Updates to use renamed function and PythonVersion formatting |
| src/usethis/_tool/impl/ruff.py | Bumps Ruff version constant from v0.14.9 to v0.14.10 |
| tests/usethis/_integrations/python/test_version.py | New comprehensive test suite for PythonVersion class covering parsing, formatting, and edge cases |
| tests/usethis/_integrations/backend/uv/test_python.py | Test updates to verify PythonVersion object structure instead of integer values |
| tests/usethis/_integrations/sonarqube/test_sonarqube_config.py | Updates test assertions to use PythonVersion string conversion |
| tests/usethis/_tool/impl/test_pytest.py | Updates imports and test assertions to use PythonVersion class |
| tests/usethis/_ui/interface/test_interface_ci.py | Updates monkeypatch targets from public to private function name |
| tests/usethis/_core/test_core_ci.py | Updates monkeypatch targets from public to private function name |
| tests/usethis/_core/test_core_tool.py | Updates to use PythonVersion class for writing version files |
| tests/usethis/_tool/impl/test_ruff.py | Adds timeout handling for GitHub API flakiness |
| tests/usethis/_tool/impl/test_pytest.py | Removes unused import from refactored version module |
| tests/usethis/_tool/impl/test_pyproject_fmt.py | Adds timeout handling for GitHub API flakiness |
| tests/usethis/_tool/impl/test_pre_commit.py | Adds timeout handling for GitHub API flakiness |
| tests/usethis/_tool/impl/test_codespell.py | Adds timeout handling and removes CI environment check |
| tests/usethis/_integrations/backend/uv/test_version.py | Adds timeout handling for GitHub API flakiness |
CodSpeed Performance ReportMerging #1216 will not alter performanceComparing Summary
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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 helps reduce duplication and adds clarity around the source for the version inference.
Also, the version of Ruff is bumped here to pass tests.
Likewise, some GitHub API flakiness is now skipped for version monitoring tests