Skip to content

Create a get_pre_commit_version function#1240

Merged
nathanjmcdougall merged 2 commits intomainfrom
1161-a-get_pre_commit_version-function
Dec 28, 2025
Merged

Create a get_pre_commit_version function#1240
nathanjmcdougall merged 2 commits intomainfrom
1161-a-get_pre_commit_version-function

Conversation

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

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.

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.
@nathanjmcdougall nathanjmcdougall linked an issue Dec 28, 2025 that may be closed by this pull request
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 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_VERSION constant 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
Copy link
Copy Markdown

codecov bot commented Dec 28, 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!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 28, 2025

CodSpeed Performance Report

Merging #1240 will not alter performance

Comparing 1161-a-get_pre_commit_version-function (2666c78) with main (1a72f58)

Summary

✅ 2 untouched

@nathanjmcdougall nathanjmcdougall merged commit 72a4cb1 into main Dec 28, 2025
19 checks passed
@nathanjmcdougall nathanjmcdougall deleted the 1161-a-get_pre_commit_version-function branch December 28, 2025 22: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.

A get_pre_commit_version function

2 participants