Create a get_pre_commit_version function#1240
Merged
nathanjmcdougall merged 2 commits intomainfrom Dec 28, 2025
Merged
Conversation
This uses the declared minimum version in the config YAML file; otherwise a hard-coded recent version. A more complex heuristic would be easy (e.g. you could look at the declared dependencies) but it seems better to keep things simple for now.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new get_pre_commit_version() function that provides a consistent way to determine the pre-commit version for usethis to target. The function uses a fallback strategy: it first attempts to read the minimum version declared in the .pre-commit-config.yaml file, and if that's not available, it falls back to a hard-coded recent version (4.5.1).
Key Changes
- Added
PRE_COMMIT_VERSIONconstant set to "4.5.1" as the hard-coded fallback - Implemented
get_pre_commit_version()function with declarative config fallback logic - Added comprehensive test coverage for all function behaviors
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/usethis/_integrations/pre_commit/version.py |
Adds the new PRE_COMMIT_VERSION constant and get_pre_commit_version() function implementation |
tests/usethis/_integrations/pre_commit/test_version.py |
Adds test class TestGetPreCommitVersion with three test cases covering declared version, missing config, and undeclared minimum scenarios |
tests/usethis/_tool/impl/test_pre_commit.py |
Adds test_latest_version() to verify the hard-coded version matches the latest GitHub release |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
CodSpeed Performance ReportMerging #1240 will not alter performanceComparing Summary
|
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 uses the declared minimum version in the config YAML file; otherwise a hard-coded recent version.
A more complex heuristic would be easy (e.g. you could look at the declared dependencies) but it seems better to keep things simple for now.