Skip to content

Move config_spec into ToolSpec#1430

Merged
nathanjmcdougall merged 5 commits intomainfrom
copilot/move-config-spec-into-toolspec
Mar 20, 2026
Merged

Move config_spec into ToolSpec#1430
nathanjmcdougall merged 5 commits intomainfrom
copilot/move-config-spec-into-toolspec

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

config_spec() lived on Tool, forcing is_likely_used() to take a separate ConfigSpec parameter alongside ToolSpec. Moving it to ToolSpec lets is_likely_used work with just a ToolSpec.

Protocol changes

  • Added config_spec() to ToolSpec (default: ConfigSpec.empty())
  • Moved get_active_config_file_managers and _get_active_config_file_managers_from_resolution from Tool to ToolSpec
  • Removed config_spec() from Tool
  • Simplified is_likely_used(tool_spec: ToolSpec) — dropped the config_spec parameter, now calls tool_spec.config_spec() internally
# Before
def is_likely_used(tool_spec: ToolSpec, config_spec: ConfigSpec) -> bool: ...

# After
def is_likely_used(tool_spec: ToolSpec) -> bool: ...

All implementations moved from impl/base/impl/spec/

All config_spec() implementations now live at the spec layer:

  • Codespell, Coverage.py, Deptry, MkDocs, Pyproject-fmt, Pytest
  • Ruff__init__ (with linter_detection / formatter_detection attrs) and config_spec() moved to RuffToolSpec
  • Import Linterconfig_spec() and helpers (_are_active_ini_contracts, _is_root_package_singular) moved to ImportLinterToolSpec
Original prompt

This section details on the original issue you should resolve

<issue_title>Move config_spec into ToolSpec</issue_title>
<issue_description>Toward #1311.

This will also mean we can refactor is_likely_used.</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 2 commits March 20, 2026 03:44
- Add config_spec() method to ToolSpec protocol in spec.py
- Move config_spec() implementations from impl/base/ to impl/spec/ for:
  codespell, coverage_py, deptry, mkdocs, pyproject_fmt, pytest
- Keep config_spec() override on impl/base/ for ruff (uses instance attrs)
  and import_linter (uses Tool methods)
- Refactor is_likely_used() to only take ToolSpec (removed config_spec param)
- Update Tool.is_used() to call simplified is_likely_used()
- Update tests accordingly

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Move config_spec into ToolSpec Move config_spec into ToolSpec Mar 20, 2026
Copilot AI requested a review from nathanjmcdougall March 20, 2026 03:47
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 99.09910% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/usethis/_tool/impl/spec/import_linter.py 97.77% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 20, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing copilot/move-config-spec-into-toolspec (f0b26bf) with main (966a19b)

Open in CodSpeed

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

@copilot you said you did this:

These override config_spec() on the Tool subclass because they depend on Tool-level state:

Ruff — uses self.linter_detection / self.formatter_detection instance attrs
Import Linter — uses Tool._get_active_config_file_managers_from_resolution() via helpers

But I want you to move the init method on RuffTool into RuffToolSpec so these ruff attrs are available at the spec level

And I want you to move get_active_config_file_managers and the helper _get_active_config_file_managers_from_resolution into the ToolSpec class too

- Move RuffTool.__init__ to RuffToolSpec so linter_detection/formatter_detection
  attrs are available at the spec level
- Move config_spec from RuffTool to RuffToolSpec
- Move config_spec and helpers (_are_active_ini_contracts, _is_root_package_singular)
  from ImportLinterTool to ImportLinterToolSpec
- Move get_active_config_file_managers and _get_active_config_file_managers_from_resolution
  from Tool to ToolSpec

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 20, 2026

@copilot you said you did this:

These override config_spec() on the Tool subclass because they depend on Tool-level state:
...

Done in b247646:

  • Moved RuffTool.__init__RuffToolSpec.__init__ (so linter_detection/formatter_detection are at the spec level)
  • Moved config_spec() from RuffToolRuffToolSpec and from ImportLinterToolImportLinterToolSpec (including _are_active_ini_contracts, _is_root_package_singular helpers)
  • Moved get_active_config_file_managers and _get_active_config_file_managers_from_resolution from ToolToolSpec

All config_spec implementations now live in impl/spec/ files. All static checks and tests pass.

@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review March 20, 2026 18:18
@nathanjmcdougall nathanjmcdougall merged commit 2ae04db into main Mar 20, 2026
17 checks passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/move-config-spec-into-toolspec branch March 20, 2026 18:18
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.

Move config_spec into ToolSpec

2 participants