Skip to content

Commit c2210e5

Browse files
Create convenience methods for bitbucket config updates (#431)
1 parent 58ea846 commit c2210e5

File tree

10 files changed

+364
-359
lines changed

10 files changed

+364
-359
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ layers = [
162162
"_app",
163163
"_interface",
164164
"_core",
165-
"_tool | _ci",
165+
"_tool",
166166
"_config_file",
167167
"_integrations",
168168
"_console",

src/usethis/_ci.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/usethis/_core/ci.py

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

3-
from usethis._ci import update_bitbucket_pytest_steps
43
from usethis._console import box_print, info_print
54
from usethis._integrations.ci.bitbucket.config import (
65
add_bitbucket_pipeline_config,
76
remove_bitbucket_pipeline_config,
87
)
9-
from usethis._integrations.ci.bitbucket.steps import (
10-
add_bitbucket_steps_in_default,
11-
)
128
from usethis._integrations.uv.init import ensure_pyproject_toml
139
from usethis._tool import (
1410
CodespellTool,
@@ -42,23 +38,18 @@ def use_ci_bitbucket(*, remove: bool = False) -> None:
4238
add_bitbucket_pipeline_config(report_placeholder=not use_any_tool)
4339

4440
if use_pre_commit:
45-
add_bitbucket_steps_in_default(PreCommitTool().get_bitbucket_steps())
41+
PreCommitTool().update_bitbucket_steps()
4642
else:
4743
# This order should match the canonical order in the function which add
4844
# steps
49-
if use_pyproject_fmt:
50-
add_bitbucket_steps_in_default(PyprojectFmtTool().get_bitbucket_steps())
51-
if use_ruff:
52-
add_bitbucket_steps_in_default(RuffTool().get_bitbucket_steps())
53-
if use_deptry:
54-
add_bitbucket_steps_in_default(DeptryTool().get_bitbucket_steps())
55-
if use_codespell:
56-
add_bitbucket_steps_in_default(CodespellTool().get_bitbucket_steps())
45+
PyprojectFmtTool().update_bitbucket_steps()
46+
RuffTool().update_bitbucket_steps()
47+
DeptryTool().update_bitbucket_steps()
48+
CodespellTool().update_bitbucket_steps()
5749

58-
if use_pytest:
59-
update_bitbucket_pytest_steps()
50+
PytestTool().update_bitbucket_steps()
6051

61-
else:
52+
if not use_pytest:
6253
info_print(
6354
"Consider `usethis tool pytest` to test your code for the pipeline."
6455
)

src/usethis/_core/tool.py

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33
from pathlib import Path
44
from typing import TYPE_CHECKING
55

6-
from usethis._ci import (
7-
is_bitbucket_used,
8-
remove_bitbucket_pytest_steps,
9-
update_bitbucket_pytest_steps,
10-
)
116
from usethis._config import usethis_config
127
from usethis._console import tick_print
13-
from usethis._integrations.ci.bitbucket.steps import (
14-
add_bitbucket_steps_in_default,
15-
remove_bitbucket_steps_from_default,
16-
)
8+
from usethis._integrations.ci.bitbucket.used import is_bitbucket_used
179
from usethis._integrations.file.pyproject_toml.valid import ensure_pyproject_validity
1810
from usethis._integrations.pre_commit.core import (
1911
install_pre_commit_hooks,
@@ -52,15 +44,14 @@ def use_codespell(*, remove: bool = False) -> None:
5244
if not remove:
5345
if not PreCommitTool().is_used():
5446
tool.add_dev_deps()
55-
if is_bitbucket_used():
56-
add_bitbucket_steps_in_default(tool.get_bitbucket_steps())
47+
tool.update_bitbucket_steps()
5748
else:
5849
tool.add_pre_commit_repo_configs()
5950

6051
tool.add_configs()
6152
tool.print_how_to_use()
6253
else:
63-
remove_bitbucket_steps_from_default(tool.get_bitbucket_steps())
54+
tool.remove_bitbucket_steps()
6455
tool.remove_configs()
6556
tool.remove_pre_commit_repo_configs()
6657
tool.remove_dev_deps()
@@ -91,14 +82,14 @@ def use_deptry(*, remove: bool = False) -> None:
9182
tool.add_dev_deps()
9283
if PreCommitTool().is_used():
9384
tool.add_pre_commit_repo_configs()
94-
elif is_bitbucket_used():
95-
add_bitbucket_steps_in_default(tool.get_bitbucket_steps())
85+
else:
86+
tool.update_bitbucket_steps()
9687

9788
tool.print_how_to_use()
9889
else:
9990
tool.remove_pre_commit_repo_configs()
10091
tool.remove_configs()
101-
remove_bitbucket_steps_from_default(tool.get_bitbucket_steps())
92+
tool.remove_bitbucket_steps()
10293
tool.remove_dev_deps()
10394
tool.remove_managed_files()
10495

@@ -133,14 +124,14 @@ def use_pre_commit(*, remove: bool = False) -> None:
133124

134125
install_pre_commit_hooks()
135126

127+
tool.update_bitbucket_steps()
136128
if is_bitbucket_used():
137-
add_bitbucket_steps_in_default(tool.get_bitbucket_steps())
138129
_remove_bitbucket_linter_steps_from_default()
139130

140131
tool.print_how_to_use()
141132
else:
133+
tool.remove_bitbucket_steps()
142134
if is_bitbucket_used():
143-
remove_bitbucket_steps_from_default(tool.get_bitbucket_steps())
144135
_add_bitbucket_linter_steps_to_default()
145136

146137
uninstall_pre_commit_hooks()
@@ -177,15 +168,15 @@ def _add_bitbucket_linter_steps_to_default() -> None:
177168
tools: list[Tool] = [PyprojectFmtTool(), DeptryTool(), RuffTool()]
178169
for tool in tools:
179170
if tool.is_used():
180-
add_bitbucket_steps_in_default(tool.get_bitbucket_steps())
171+
tool.update_bitbucket_steps()
181172

182173

183174
def _remove_bitbucket_linter_steps_from_default() -> None:
184175
# This order of removing tools should be synced with the order hard-coded
185176
# in the function which adds steps.
186-
remove_bitbucket_steps_from_default(PyprojectFmtTool().get_bitbucket_steps())
187-
remove_bitbucket_steps_from_default(DeptryTool().get_bitbucket_steps())
188-
remove_bitbucket_steps_from_default(RuffTool().get_bitbucket_steps())
177+
PyprojectFmtTool().remove_bitbucket_steps()
178+
DeptryTool().remove_bitbucket_steps()
179+
RuffTool().remove_bitbucket_steps()
189180

190181

191182
def use_pyproject_fmt(*, remove: bool = False) -> None:
@@ -196,15 +187,14 @@ def use_pyproject_fmt(*, remove: bool = False) -> None:
196187
if not remove:
197188
if not PreCommitTool().is_used():
198189
tool.add_dev_deps()
199-
if is_bitbucket_used():
200-
add_bitbucket_steps_in_default(tool.get_bitbucket_steps())
190+
tool.update_bitbucket_steps()
201191
else:
202192
tool.add_pre_commit_repo_configs()
203193

204194
tool.add_configs()
205195
tool.print_how_to_use()
206196
else:
207-
remove_bitbucket_steps_from_default(tool.get_bitbucket_steps())
197+
tool.remove_bitbucket_steps()
208198
tool.remove_configs()
209199
tool.remove_pre_commit_repo_configs()
210200
tool.remove_dev_deps()
@@ -239,16 +229,14 @@ def use_pytest(*, remove: bool = False) -> None:
239229
# https://github.com/fpgmaas/deptry/issues/302
240230
add_pytest_dir()
241231

242-
if is_bitbucket_used():
243-
update_bitbucket_pytest_steps()
232+
PytestTool().update_bitbucket_steps()
244233

245234
tool.print_how_to_use()
246235

247236
if CoverageTool().is_used():
248237
CoverageTool().print_how_to_use()
249238
else:
250-
if is_bitbucket_used():
251-
remove_bitbucket_pytest_steps()
239+
PytestTool().remove_bitbucket_steps()
252240

253241
if RuffTool().is_used():
254242
RuffTool().deselect_rules(tool.get_associated_ruff_rules())
@@ -342,13 +330,13 @@ def use_ruff(*, remove: bool = False) -> None:
342330
tool.ignore_rules(ignored_rules)
343331
if PreCommitTool().is_used():
344332
tool.add_pre_commit_repo_configs()
345-
elif is_bitbucket_used():
346-
add_bitbucket_steps_in_default(tool.get_bitbucket_steps())
333+
else:
334+
tool.update_bitbucket_steps()
347335

348336
tool.print_how_to_use()
349337
else:
350338
tool.remove_pre_commit_repo_configs()
351-
remove_bitbucket_steps_from_default(tool.get_bitbucket_steps())
339+
tool.remove_bitbucket_steps()
352340
tool.remove_configs()
353341
tool.remove_dev_deps()
354342
tool.remove_managed_files()

src/usethis/_integrations/ci/bitbucket/steps.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@
6464
script_item.yaml_set_anchor(value=name, always_dump=True)
6565

6666

67-
def add_bitbucket_steps_in_default(steps: list[Step]) -> None:
68-
for step in steps:
69-
add_bitbucket_step_in_default(step)
70-
71-
7267
def add_bitbucket_step_in_default(step: Step) -> None:
7368
try:
7469
existing_steps = get_steps_in_default()
@@ -187,11 +182,6 @@ def _add_step_in_default_via_doc(
187182
)
188183

189184

190-
def remove_bitbucket_steps_from_default(steps: list[Step]) -> None:
191-
for step in steps:
192-
remove_bitbucket_step_from_default(step)
193-
194-
195185
def remove_bitbucket_step_from_default(step: Step) -> None:
196186
"""Remove a step from the default pipeline in the Bitbucket Pipelines configuration.
197187
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
5+
6+
def is_bitbucket_used() -> bool:
7+
return (Path.cwd() / "bitbucket-pipelines.yml").exists()

0 commit comments

Comments
 (0)