Skip to content

Create standalone functions for default Tool methods #1350

@nathanjmcdougall

Description

@nathanjmcdougall

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

Metadata

Metadata

Labels

internalChanges to the internals without changing interfaces

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions