11from __future__ import annotations
22
3+ from typing import TYPE_CHECKING
4+
35from usethis ._console import how_print , info_print
46from usethis ._integrations .ci .bitbucket .config import (
57 add_bitbucket_pipelines_config ,
1315from usethis ._tool .impl .pytest import PytestTool
1416from 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
1733def 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+
6063def 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