Skip to content

Commit e3cb1f9

Browse files
committed
Format files with black, update workflow to create PR with black formatted code if code isn't formatted already
1 parent 92e06ab commit e3cb1f9

File tree

3 files changed

+132
-63
lines changed

3 files changed

+132
-63
lines changed

.github/workflows/black.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,37 @@ name: Lint
22

33
on: [push, pull_request]
44

5+
permissions:
6+
contents: write
7+
pull-requests: write
8+
59
jobs:
610
lint:
711
runs-on: ubuntu-latest
812
steps:
913
- uses: actions/checkout@v4
10-
- uses: psf/black@stable
1114
with:
12-
options: "--check --verbose"
13-
src: "./bbox_visualizer/bbox_visualizer.py ./tests/test_bbox_visualizer.py"
14-
use_pyproject: true
15+
ref: ${{ github.head_ref }}
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.x'
21+
22+
- name: Install Black
23+
run: pip install black
24+
25+
- name: Run Black
26+
run: black bbox_visualizer/bbox_visualizer.py tests/test_bbox_visualizer.py
27+
28+
- name: Create Pull Request
29+
uses: peter-evans/create-pull-request@v5
30+
with:
31+
commit-message: "style: format code with Black"
32+
title: "style: format code with Black"
33+
body: |
34+
Auto-formatted code with Black.
35+
36+
This PR was automatically created by the Black formatting GitHub Action.
37+
branch: format-code-with-black
38+
delete-branch: true

bbox_visualizer/bbox_visualizer.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88

99
def check_and_modify_bbox(
10-
bbox: List[int],
11-
img_size: Tuple[int, int, int],
12-
margin: int = 0
10+
bbox: List[int], img_size: Tuple[int, int, int], margin: int = 0
1311
) -> List[int]:
1412
"""Checks and adjusts bounding box coordinates to fit within image boundaries.
1513
@@ -37,7 +35,7 @@ def draw_rectangle(
3735
bbox_color: Tuple[int, int, int] = (255, 255, 255),
3836
thickness: int = 3,
3937
is_opaque: bool = False,
40-
alpha: float = 0.5
38+
alpha: float = 0.5,
4139
) -> np.ndarray:
4240
"""Draws a rectangle around an object in the image.
4341
@@ -105,7 +103,7 @@ def add_label(
105103
# Calculate background rectangle dimensions
106104
bg_width = text_width + 2 * padding
107105
bg_height = text_height + 2 * padding
108-
106+
109107
# Calculate background rectangle position
110108
bg_x1 = bbox[0]
111109
bg_y1 = bbox[1] - bg_height # Removed the gap by removing (5 * size)
@@ -138,7 +136,7 @@ def add_label(
138136
# Calculate background rectangle dimensions
139137
bg_width = text_width + 2 * padding
140138
bg_height = text_height + 2 * padding
141-
139+
142140
# Calculate background rectangle position
143141
bg_x1 = bbox[0]
144142
bg_y1 = bbox[1]
@@ -203,7 +201,7 @@ def add_T_label(
203201
label, font, size, thickness
204202
)
205203
padding = 5 # Padding around text
206-
204+
207205
# draw vertical line
208206
x_center = (bbox[0] + bbox[2]) // 2
209207
line_top = y_top = bbox[1] - 50
@@ -219,11 +217,11 @@ def add_T_label(
219217
return add_label(img, label, bbox)
220218

221219
cv2.line(img, (x_center, bbox[1]), (x_center, line_top), text_bg_color, 3)
222-
220+
223221
# Calculate background rectangle dimensions
224222
bg_width = label_width + 2 * padding
225223
bg_height = label_height + 2 * padding
226-
224+
227225
# Calculate background rectangle position
228226
bg_x1 = x_center - (bg_width // 2)
229227
bg_y1 = y_top
@@ -336,7 +334,7 @@ def draw_multiple_rectangles(
336334
bbox_color: Tuple[int, int, int] = (255, 255, 255),
337335
thickness: int = 3,
338336
is_opaque: bool = False,
339-
alpha: float = 0.5
337+
alpha: float = 0.5,
340338
) -> np.ndarray:
341339
"""Draws multiple rectangles on the image.
342340

0 commit comments

Comments
 (0)