11from pathlib import Path
22
33from usethis ._ci import (
4- add_bitbucket_pre_commit_step ,
4+ get_bitbucket_deptry_step ,
5+ get_bitbucket_pre_commit_step ,
6+ get_bitbucket_pyproject_fmt_step ,
7+ get_bitbucket_ruff_step ,
58 is_bitbucket_used ,
6- remove_bitbucket_pre_commit_step ,
79 remove_bitbucket_pytest_steps ,
810 update_bitbucket_pytest_steps ,
911)
1012from usethis ._console import box_print , tick_print
13+ from usethis ._integrations .bitbucket .steps import (
14+ add_bitbucket_step_in_default ,
15+ remove_bitbucket_step_from_default ,
16+ )
1117from usethis ._integrations .pre_commit .core import (
1218 install_pre_commit_hooks ,
1319 remove_pre_commit_config ,
@@ -78,11 +84,14 @@ def use_deptry(*, remove: bool = False) -> None:
7884 add_deps_to_group (tool .dev_deps , "dev" )
7985 if PreCommitTool ().is_used ():
8086 tool .add_pre_commit_repo_configs ()
87+ elif is_bitbucket_used ():
88+ add_bitbucket_step_in_default (get_bitbucket_deptry_step ())
8189
8290 box_print ("Run 'deptry src' to run deptry." )
8391 else :
84- if PreCommitTool ().is_used ():
85- tool .remove_pre_commit_repo_configs ()
92+ tool .remove_pre_commit_repo_configs ()
93+ remove_bitbucket_step_from_default (get_bitbucket_deptry_step ())
94+
8695 remove_deps_from_group (tool .dev_deps , "dev" )
8796
8897
@@ -113,12 +122,14 @@ def use_pre_commit(*, remove: bool = False) -> None:
113122 install_pre_commit_hooks ()
114123
115124 if is_bitbucket_used ():
116- add_bitbucket_pre_commit_step ()
125+ add_bitbucket_step_in_default (get_bitbucket_pre_commit_step ())
126+ _remove_bitbucket_linter_steps_from_default ()
117127
118128 box_print ("Run 'pre-commit run --all-files' to run the hooks manually." )
119129 else :
120130 if is_bitbucket_used ():
121- remove_bitbucket_pre_commit_step ()
131+ remove_bitbucket_step_from_default (get_bitbucket_pre_commit_step ())
132+ _add_bitbucket_linter_steps_to_default ()
122133
123134 # Need pre-commit to be installed so we can uninstall hooks
124135 add_deps_to_group (tool .dev_deps , "dev" )
@@ -139,6 +150,26 @@ def use_pre_commit(*, remove: bool = False) -> None:
139150 _requirements_txt_instructions_basic ()
140151
141152
153+ def _add_bitbucket_linter_steps_to_default () -> None :
154+ # This order of adding tools should be synced with the order hard-coded
155+ # in the function which adds steps.
156+ if is_bitbucket_used ():
157+ if PyprojectFmtTool ().is_used ():
158+ add_bitbucket_step_in_default (get_bitbucket_pyproject_fmt_step ())
159+ if DeptryTool ().is_used ():
160+ add_bitbucket_step_in_default (get_bitbucket_deptry_step ())
161+ if RuffTool ().is_used ():
162+ add_bitbucket_step_in_default (get_bitbucket_ruff_step ())
163+
164+
165+ def _remove_bitbucket_linter_steps_from_default () -> None :
166+ # This order of removing tools should be synced with the order hard-coded
167+ # in the function which adds steps.
168+ remove_bitbucket_step_from_default (get_bitbucket_pyproject_fmt_step ())
169+ remove_bitbucket_step_from_default (get_bitbucket_deptry_step ())
170+ remove_bitbucket_step_from_default (get_bitbucket_ruff_step ())
171+
172+
142173def use_pyproject_fmt (* , remove : bool = False ) -> None :
143174 tool = PyprojectFmtTool ()
144175
@@ -149,6 +180,8 @@ def use_pyproject_fmt(*, remove: bool = False) -> None:
149180
150181 if not is_pre_commit :
151182 add_deps_to_group (tool .dev_deps , "dev" )
183+ if is_bitbucket_used ():
184+ add_bitbucket_step_in_default (get_bitbucket_pyproject_fmt_step ())
152185 else :
153186 tool .add_pre_commit_repo_configs ()
154187
@@ -159,9 +192,9 @@ def use_pyproject_fmt(*, remove: bool = False) -> None:
159192 else :
160193 _pyproject_fmt_instructions_pre_commit ()
161194 else :
195+ remove_bitbucket_step_from_default (get_bitbucket_pyproject_fmt_step ())
162196 tool .remove_pyproject_configs ()
163- if PreCommitTool ().is_used ():
164- tool .remove_pre_commit_repo_configs ()
197+ tool .remove_pre_commit_repo_configs ()
165198 remove_deps_from_group (tool .dev_deps , "dev" )
166199
167200
@@ -252,8 +285,7 @@ def use_requirements_txt(*, remove: bool = False) -> None:
252285 else :
253286 _requirements_txt_instructions_pre_commit ()
254287 else :
255- if PreCommitTool ().is_used ():
256- tool .remove_pre_commit_repo_configs ()
288+ tool .remove_pre_commit_repo_configs ()
257289
258290 if path .exists () and path .is_file ():
259291 tick_print ("Removing 'requirements.txt'." )
@@ -306,11 +338,13 @@ def use_ruff(*, remove: bool = False) -> None:
306338 ignore_ruff_rules (ignored_rules )
307339 if PreCommitTool ().is_used ():
308340 tool .add_pre_commit_repo_configs ()
341+ elif is_bitbucket_used ():
342+ add_bitbucket_step_in_default (get_bitbucket_ruff_step ())
309343
310344 box_print ("Run 'ruff check --fix' to run the Ruff linter with autofixes." )
311345 box_print ("Run 'ruff format' to run the Ruff formatter." )
312346 else :
313- if PreCommitTool (). is_used ():
314- tool . remove_pre_commit_repo_configs ( )
347+ tool . remove_pre_commit_repo_configs ()
348+ remove_bitbucket_step_from_default ( get_bitbucket_ruff_step () )
315349 tool .remove_pyproject_configs () # N.B. this will remove the selected Ruff rules
316350 remove_deps_from_group (tool .dev_deps , "dev" )
0 commit comments