Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions src/usethis/_core/ci.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from usethis._console import how_print, info_print
from usethis._integrations.ci.bitbucket.config import (
add_bitbucket_pipelines_config,
Expand All @@ -13,6 +15,20 @@
from usethis._tool.impl.pytest import PytestTool
from usethis._tool.impl.ruff import RuffTool

if TYPE_CHECKING:
from usethis._tool.base import Tool

# These are tools would run via pre-commit if available
_CI_QA_TOOLS: list[type[Tool]] = [ # Not including pytest and pre-commit
# This order should match the canonical order in the function which adds
# steps
PyprojectFmtTool,
RuffTool,
DeptryTool,
ImportLinterTool,
CodespellTool,
]


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

if not remove:
use_pre_commit = PreCommitTool().is_used()
use_pytest = PytestTool().is_used()
use_ruff = RuffTool().is_used()
use_deptry = DeptryTool().is_used()
use_import_linter = ImportLinterTool().is_used()
use_pyproject_fmt = PyprojectFmtTool().is_used()
use_codespell = CodespellTool().is_used()
use_any_tool = (
use_pre_commit
or use_pytest
or use_ruff
or use_deptry
or use_import_linter
or use_pyproject_fmt
or use_codespell
use_pre_commit or PytestTool().is_used() or _using_any_ci_qa_tools()
)

add_bitbucket_pipelines_config(report_placeholder=not use_any_tool)

if use_pre_commit:
PreCommitTool().update_bitbucket_steps()
else:
# This order should match the canonical order in the function which adds
# steps
PyprojectFmtTool().update_bitbucket_steps()
RuffTool().update_bitbucket_steps()
DeptryTool().update_bitbucket_steps()
ImportLinterTool().update_bitbucket_steps()
CodespellTool().update_bitbucket_steps()
for tool in _CI_QA_TOOLS:
tool().update_bitbucket_steps()

PytestTool().update_bitbucket_steps()

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


def _using_any_ci_qa_tools():
return any(tool().is_used() for tool in _CI_QA_TOOLS)


def print_how_to_use_ci_bitbucket() -> None:
"""Print how to use the Bitbucket CI service."""
if not PytestTool().is_used():
info_print("Consider `usethis tool pytest` to test your code for the pipeline.")
_suggest_pytest()

how_print("Run your pipeline via the Bitbucket website.")


def _suggest_pytest() -> None:
if not PytestTool().is_used():
info_print("Consider `usethis tool pytest` to test your code for the pipeline.")