1
1
from pathlib import Path
2
2
3
3
from 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 ,
5
8
is_bitbucket_used ,
6
- remove_bitbucket_pre_commit_step ,
7
9
remove_bitbucket_pytest_steps ,
8
10
update_bitbucket_pytest_steps ,
9
11
)
10
12
from 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
+ )
11
17
from usethis ._integrations .pre_commit .core import (
12
18
install_pre_commit_hooks ,
13
19
remove_pre_commit_config ,
@@ -78,11 +84,14 @@ def use_deptry(*, remove: bool = False) -> None:
78
84
add_deps_to_group (tool .dev_deps , "dev" )
79
85
if PreCommitTool ().is_used ():
80
86
tool .add_pre_commit_repo_configs ()
87
+ elif is_bitbucket_used ():
88
+ add_bitbucket_step_in_default (get_bitbucket_deptry_step ())
81
89
82
90
box_print ("Run 'deptry src' to run deptry." )
83
91
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
+
86
95
remove_deps_from_group (tool .dev_deps , "dev" )
87
96
88
97
@@ -113,12 +122,14 @@ def use_pre_commit(*, remove: bool = False) -> None:
113
122
install_pre_commit_hooks ()
114
123
115
124
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 ()
117
127
118
128
box_print ("Run 'pre-commit run --all-files' to run the hooks manually." )
119
129
else :
120
130
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 ()
122
133
123
134
# Need pre-commit to be installed so we can uninstall hooks
124
135
add_deps_to_group (tool .dev_deps , "dev" )
@@ -139,6 +150,26 @@ def use_pre_commit(*, remove: bool = False) -> None:
139
150
_requirements_txt_instructions_basic ()
140
151
141
152
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
+
142
173
def use_pyproject_fmt (* , remove : bool = False ) -> None :
143
174
tool = PyprojectFmtTool ()
144
175
@@ -149,6 +180,8 @@ def use_pyproject_fmt(*, remove: bool = False) -> None:
149
180
150
181
if not is_pre_commit :
151
182
add_deps_to_group (tool .dev_deps , "dev" )
183
+ if is_bitbucket_used ():
184
+ add_bitbucket_step_in_default (get_bitbucket_pyproject_fmt_step ())
152
185
else :
153
186
tool .add_pre_commit_repo_configs ()
154
187
@@ -159,9 +192,9 @@ def use_pyproject_fmt(*, remove: bool = False) -> None:
159
192
else :
160
193
_pyproject_fmt_instructions_pre_commit ()
161
194
else :
195
+ remove_bitbucket_step_from_default (get_bitbucket_pyproject_fmt_step ())
162
196
tool .remove_pyproject_configs ()
163
- if PreCommitTool ().is_used ():
164
- tool .remove_pre_commit_repo_configs ()
197
+ tool .remove_pre_commit_repo_configs ()
165
198
remove_deps_from_group (tool .dev_deps , "dev" )
166
199
167
200
@@ -252,8 +285,7 @@ def use_requirements_txt(*, remove: bool = False) -> None:
252
285
else :
253
286
_requirements_txt_instructions_pre_commit ()
254
287
else :
255
- if PreCommitTool ().is_used ():
256
- tool .remove_pre_commit_repo_configs ()
288
+ tool .remove_pre_commit_repo_configs ()
257
289
258
290
if path .exists () and path .is_file ():
259
291
tick_print ("Removing 'requirements.txt'." )
@@ -306,11 +338,13 @@ def use_ruff(*, remove: bool = False) -> None:
306
338
ignore_ruff_rules (ignored_rules )
307
339
if PreCommitTool ().is_used ():
308
340
tool .add_pre_commit_repo_configs ()
341
+ elif is_bitbucket_used ():
342
+ add_bitbucket_step_in_default (get_bitbucket_ruff_step ())
309
343
310
344
box_print ("Run 'ruff check --fix' to run the Ruff linter with autofixes." )
311
345
box_print ("Run 'ruff format' to run the Ruff formatter." )
312
346
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 () )
315
349
tool .remove_pyproject_configs () # N.B. this will remove the selected Ruff rules
316
350
remove_deps_from_group (tool .dev_deps , "dev" )
0 commit comments