Skip to content

Commit 20a9a19

Browse files
Introduce new is_config_present helper function in Tool abc (#652)
1 parent fa1a1e8 commit 20a9a19

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/usethis/_tool/base.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,7 @@ def is_used(self) -> bool:
106106
for dep in self.get_test_deps(unconditional=True):
107107
if is_dep_in_any_group(dep):
108108
return True
109-
config_spec = self.get_config_spec()
110-
for config_item in config_spec.config_items:
111-
if not config_item.managed:
112-
continue
113-
114-
for path, entry in config_item.root.items():
115-
file_manager = config_spec.file_manager_by_relative_path[path]
116-
if file_manager.__contains__(entry.keys):
117-
return True
118-
119-
return False
109+
return self.is_config_present()
120110

121111
def add_dev_deps(self) -> None:
122112
add_deps_to_group(self.get_dev_deps(), "dev")
@@ -234,6 +224,20 @@ def preferred_file_manager(self) -> KeyValueFileManager:
234224
"""If there is no currently active config file, this is the preferred one."""
235225
return PyprojectTOMLManager()
236226

227+
def is_config_present(self) -> bool:
228+
"""Whether any of the tool's managed config sections are present."""
229+
config_spec = self.get_config_spec()
230+
for config_item in config_spec.config_items:
231+
if not config_item.managed:
232+
continue
233+
234+
for path, entry in config_item.root.items():
235+
file_manager = config_spec.file_manager_by_relative_path[path]
236+
if file_manager.__contains__(entry.keys):
237+
return True
238+
239+
return False
240+
237241
def add_configs(self) -> None:
238242
"""Add the tool's configuration sections."""
239243
# Principles:

0 commit comments

Comments
 (0)