Skip to content

Commit 77bf493

Browse files
Refactor the src\usethis\_core\ci.py module
1 parent 8669b6d commit 77bf493

1 file changed

Lines changed: 29 additions & 22 deletions

File tree

src/usethis/_core/ci.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import TYPE_CHECKING
4+
35
from usethis._console import how_print, info_print
46
from usethis._integrations.ci.bitbucket.config import (
57
add_bitbucket_pipelines_config,
@@ -13,6 +15,20 @@
1315
from usethis._tool.impl.pytest import PytestTool
1416
from usethis._tool.impl.ruff import RuffTool
1517

18+
if TYPE_CHECKING:
19+
from usethis._tool.base import Tool
20+
21+
# These are tools would run via pre-commit if available
22+
_CI_QA_TOOLS: list[type[Tool]] = [ # Not including pytest and pre-commit
23+
# This order should match the canonical order in the function which adds
24+
# steps
25+
PyprojectFmtTool,
26+
RuffTool,
27+
DeptryTool,
28+
ImportLinterTool,
29+
CodespellTool,
30+
]
31+
1632

1733
def use_ci_bitbucket(*, remove: bool = False, how: bool = False) -> None:
1834
if how:
@@ -21,34 +37,17 @@ def use_ci_bitbucket(*, remove: bool = False, how: bool = False) -> None:
2137

2238
if not remove:
2339
use_pre_commit = PreCommitTool().is_used()
24-
use_pytest = PytestTool().is_used()
25-
use_ruff = RuffTool().is_used()
26-
use_deptry = DeptryTool().is_used()
27-
use_import_linter = ImportLinterTool().is_used()
28-
use_pyproject_fmt = PyprojectFmtTool().is_used()
29-
use_codespell = CodespellTool().is_used()
3040
use_any_tool = (
31-
use_pre_commit
32-
or use_pytest
33-
or use_ruff
34-
or use_deptry
35-
or use_import_linter
36-
or use_pyproject_fmt
37-
or use_codespell
41+
use_pre_commit or PytestTool().is_used() or _using_any_ci_qa_tools()
3842
)
3943

4044
add_bitbucket_pipelines_config(report_placeholder=not use_any_tool)
4145

4246
if use_pre_commit:
4347
PreCommitTool().update_bitbucket_steps()
4448
else:
45-
# This order should match the canonical order in the function which adds
46-
# steps
47-
PyprojectFmtTool().update_bitbucket_steps()
48-
RuffTool().update_bitbucket_steps()
49-
DeptryTool().update_bitbucket_steps()
50-
ImportLinterTool().update_bitbucket_steps()
51-
CodespellTool().update_bitbucket_steps()
49+
for tool in _CI_QA_TOOLS:
50+
tool().update_bitbucket_steps()
5251

5352
PytestTool().update_bitbucket_steps()
5453

@@ -57,9 +56,17 @@ def use_ci_bitbucket(*, remove: bool = False, how: bool = False) -> None:
5756
remove_bitbucket_pipelines_config()
5857

5958

59+
def _using_any_ci_qa_tools():
60+
return any(tool().is_used() for tool in _CI_QA_TOOLS)
61+
62+
6063
def print_how_to_use_ci_bitbucket() -> None:
6164
"""Print how to use the Bitbucket CI service."""
62-
if not PytestTool().is_used():
63-
info_print("Consider `usethis tool pytest` to test your code for the pipeline.")
65+
_suggest_pytest()
6466

6567
how_print("Run your pipeline via the Bitbucket website.")
68+
69+
70+
def _suggest_pytest() -> None:
71+
if not PytestTool().is_used():
72+
info_print("Consider `usethis tool pytest` to test your code for the pipeline.")

0 commit comments

Comments
 (0)