Skip to content

Commit 112b2f4

Browse files
Introduce screening check before is_used to reduce I/O
1 parent a4908fa commit 112b2f4

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/usethis/_core/tool.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,10 @@ def use_pytest(*, remove: bool = False, how: bool = False) -> None:
327327
if isinstance(_tool, PytestTool):
328328
continue
329329

330-
if _tool.is_used():
331-
rule_config |= _tool.get_rule_config().subset_related_to_tests()
330+
config = _tool.get_rule_config()
331+
332+
if config.is_related_to_tests and _tool.is_used():
333+
rule_config |= config.subset_related_to_tests()
332334

333335
if RuffTool().is_used():
334336
RuffTool().apply_rule_config(rule_config)

src/usethis/_tool/rule.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ def empty(self) -> bool:
7070
and not self.tests_unmanaged_ignored
7171
)
7272

73+
@property
74+
def is_related_to_tests(self) -> bool:
75+
"""Check if the rule config has any tests-related rules."""
76+
return bool(self.tests_unmanaged_ignored)
77+
7378
def __repr__(self) -> str:
7479
"""Representation which omits empty-list fields."""
7580
args = []

0 commit comments

Comments
 (0)