Skip to content

Refactor Tool defaults into standalone ToolSpec methods and is_likely_used function#1351

Merged
nathanjmcdougall merged 3 commits intomainfrom
copilot/create-standalone-tool-functions
Mar 10, 2026
Merged

Refactor Tool defaults into standalone ToolSpec methods and is_likely_used function#1351
nathanjmcdougall merged 3 commits intomainfrom
copilot/create-standalone-tool-functions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 10, 2026

  • Create usethis/_tool/spec.py with ToolMeta and ToolSpec (moved from base.py), adding is_declared_as_dep, get_pre_commit_repos, is_pre_commit_config_present to ToolSpec
  • Add is_present method to ConfigSpec in usethis/_tool/config.py (moved from Tool._is_config_spec_present)
  • Create usethis/_tool/heuristics.py with standalone is_likely_used(tool_spec, config_spec) function
  • Update usethis/_tool/base.py: import from spec.py, refactor Tool.is_used to use is_likely_used, update is_config_present to use ConfigSpec.is_present, remove _is_config_spec_present/is_declared_as_dep/get_pre_commit_repos/is_pre_commit_config_present from Tool
  • Update usethis/_tool/impl/ruff.py to use config_spec.is_present() instead of self._is_config_spec_present(...)
  • Keep ToolMeta/ToolSpec re-exported from base.py for backward compatibility
  • Update .importlinter to add heuristics and spec layers
  • Add tests for is_likely_used in tests/usethis/_tool/test_heuristics.py
  • Add test TestConfigSpecIsPresent::test_unmanaged_item_not_detected covering the managed=False continue branch in ConfigSpec.is_present()
  • Run linting (ruff), type checker (ty), and import linter - all pass
Original prompt

This section details on the original issue you should resolve

<issue_title>Create standalone functions for default Tool methods</issue_title>
<issue_description>Toward #1311, we want a standalone is_likely_used function which would take a ToolSpec and ConfigSpec and basically just give the current implementation for Tool.is_used, i.e. the default implementation.

Tool.is_used would be refactored to use is_likely_used using self for the ToolSpec and self.config_spec for the ConfigSpec.

Tool.is_used, whose current implementation would serve as the basis for is_likely_used, currently uses Tool.is_declared_as_dep, which should be moved into ToolSpec so it is accessible from the ToolSpec arg. It also uses Tool.is_config_present which uses a Tool._is_config_spec_present helper method together with ConfigSpec from Tool.config_spec. We should move the Tool._is_config_spec_present method to ConfigSpec.is_present since it doesn't actually use the self arg in Tool at all. Then, is_likely_used can just use ConfigSpec.is_present directly from the ConfigSpec passed as an argument.

Lastly, Tool.is_used uses Tool.is_pre_commit_config_present. This, along with its dependent method Tool.get_pre_commit_repos should be moved into ToolSpec.

The ToolSpec implementation should be moved into a new module called usethis._tool.spec.

The new standalone is_likely_used method should be put into a new usethis._tool.heuristics module.

The new module layering for usethis._tool should be like the following:
layers =
all_
impl
base
heuristics
spec
config | pre_commit | rule</issue_description>

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


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…odule

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Add standalone functions for Tool methods Refactor Tool defaults into standalone ToolSpec methods and is_likely_used function Mar 10, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 10, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing copilot/create-standalone-tool-functions (a2e09d5) with main (c3cf2b6)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 10, 2026

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!

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review March 10, 2026 06:37
@nathanjmcdougall nathanjmcdougall merged commit 0aa2eed into main Mar 10, 2026
20 checks passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/create-standalone-tool-functions branch March 10, 2026 06:37
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.

Create standalone functions for default Tool methods

2 participants