Title: Add `PreCommitConfig.from_system_hook()` to deduplicate backend dispatch in tool specs by Copilot · Pull Request #1606 · usethis-python/usethis-python · GitHub
Open Graph Title: Add `PreCommitConfig.from_system_hook()` to deduplicate backend dispatch in tool specs by Copilot · Pull Request #1606 · usethis-python/usethis-python
X Title: Add `PreCommitConfig.from_system_hook()` to deduplicate backend dispatch in tool specs by Copilot · Pull Request #1606 · usethis-python/usethis-python
Description: Three tool specs (ty, deptry, import_linter) each duplicated ~40 lines of identical backend dispatch logic to construct a local system hook PreCommitConfig. This adds a single classmethod that encapsulates the pattern. New method PreCommitConfig.from_system_hook() handles backend dispatch (prefixing uv run --frozen --offline for uv), system language resolution, and LocalRepo construction internally. It takes only two parameters (hook_id and entry) and hardcodes the common defaults (always_run=True, pass_filenames=False, requires_venv=True, inform_how_to_use_on_migrate=False): # Before: ~40 lines of if/elif/else per tool backend = get_backend() if backend is BackendEnum.uv: return PreCommitConfig.from_single_repo( pre_commit_schema.LocalRepo(repo="local", hooks=[ pre_commit_schema.HookDefinition( id="ty", name="ty", entry="uv run --frozen --offline ty check", language=get_system_language(), ... ) ]), requires_venv=True, inform_how_to_use_on_migrate=False, ) elif backend is BackendEnum.none: # Same thing without the uv prefix... else: assert_never(backend) # After return PreCommitConfig.from_system_hook( hook_id="ty", entry="ty check", ) Changes src/usethis/_tool/pre_commit.py — Added from_system_hook() classmethod with 2 params (hook_id, entry), hardcoding always_run=True, pass_filenames=False src/usethis/_tool/impl/spec/{ty,deptry,import_linter}.py — Replaced backend dispatch blocks with single from_system_hook() calls; removed now-unused imports (get_backend, assert_never, BackendEnum, pre_commit_schema, get_system_language) tests/usethis/_tool/test_pre_commit.py — 10 tests covering both backends, all hook fields, and hardcoded defaults 📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.
Open Graph Description: Three tool specs (ty, deptry, import_linter) each duplicated ~40 lines of identical backend dispatch logic to construct a local system hook PreCommitConfig. This adds a single classmethod that enca...
X Description: Three tool specs (ty, deptry, import_linter) each duplicated ~40 lines of identical backend dispatch logic to construct a local system hook PreCommitConfig. This adds a single classmethod that enca...
Opengraph URL: https://github.com/usethis-python/usethis-python/pull/1606
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:8c281425-755a-1926-0d8a-f6bc0fffa5f4 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BF30:179658:FB4553:16F95C8:6A4E35C2 |
| html-safe-nonce | f0651ef43a67158f7dc3264f58721e206c8159b42a820d1be7670621bec971f8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRjMwOjE3OTY1ODpGQjQ1NTM6MTZGOTVDODo2QTRFMzVDMiIsInZpc2l0b3JfaWQiOiIyODI1Nzg2NDkwNTE2MDI2ODE4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f7f2dfdbfec9be9f80d7b912e958f60f5e170903c5c420224a675dc76dcdbc17 |
| hovercard-subject-tag | pull_request:3456558804 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/usethis-python/usethis-python/pull/1606/files |
| twitter:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| og:image:alt | Three tool specs (ty, deptry, import_linter) each duplicated ~40 lines of identical backend dispatch logic to construct a local system hook PreCommitConfig. This adds a single classmethod that enca... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/usethis-python/usethis-python git https://github.com/usethis-python/usethis-python.git |
| octolytics-dimension-user_id | 216362695 |
| octolytics-dimension-user_login | usethis-python |
| octolytics-dimension-repository_id | 842189705 |
| octolytics-dimension-repository_nwo | usethis-python/usethis-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 842189705 |
| octolytics-dimension-repository_network_root_nwo | usethis-python/usethis-python |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 42a6d378d7587a44c93aca255096cd66b7c8eb2d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width