Skip to content

Refactor Python version logic into a dedicated class#1216

Merged
nathanjmcdougall merged 1 commit intomainfrom
1106-unify-the-logic-for-inferring-python-versions-for-sonarqube-vs-overall-project
Dec 23, 2025
Merged

Refactor Python version logic into a dedicated class#1216
nathanjmcdougall merged 1 commit intomainfrom
1106-unify-the-logic-for-inferring-python-versions-for-sonarqube-vs-overall-project

Conversation

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

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

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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PythonVersion dataclass with from_string(), from_interpreter(), and to_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-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 23, 2025

CodSpeed Performance Report

Merging #1216 will not alter performance

Comparing 1106-unify-the-logic-for-inferring-python-versions-for-sonarqube-vs-overall-project (61762e5) with main (e2e9934)

Summary

✅ 2 untouched

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@nathanjmcdougall nathanjmcdougall merged commit 8a49dbc into main Dec 23, 2025
20 checks passed
@nathanjmcdougall nathanjmcdougall deleted the 1106-unify-the-logic-for-inferring-python-versions-for-sonarqube-vs-overall-project branch December 23, 2025 04:23
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.

Unify the logic for inferring Python versions for SonarQube vs. overall project

2 participants