Skip to content

Commit 4f816cf

Browse files
authored
Merge pull request #38 from shoumikchow/dev
2 parents ef685c3 + 7078bef commit 4f816cf

26 files changed

+429
-204
lines changed

.github/workflows/black.yml

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

.github/workflows/ruff.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Ruff
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: write
7+
pull-requests: write
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: "3.x"
21+
22+
- name: Install Ruff
23+
run: pip install ruff
24+
25+
- name: Run Ruff Format Check
26+
id: ruff-format
27+
continue-on-error: true
28+
run: |
29+
ruff format --check bbox_visualizer tests examples
30+
echo "format_changes=$?" >> $GITHUB_OUTPUT
31+
32+
- name: Run Ruff Lint Check
33+
id: ruff-lint
34+
continue-on-error: true
35+
run: |
36+
ruff check bbox_visualizer tests examples
37+
echo "lint_changes=$?" >> $GITHUB_OUTPUT
38+
39+
- name: Format and Fix with Ruff if needed
40+
if: steps.ruff-format.outputs.format_changes == '1' || steps.ruff-lint.outputs.lint_changes == '1'
41+
run: |
42+
ruff format bbox_visualizer tests examples
43+
ruff check --fix bbox_visualizer tests examples
44+
45+
- name: Create Pull Request
46+
if: steps.ruff-format.outputs.format_changes == '1' || steps.ruff-lint.outputs.lint_changes == '1'
47+
uses: peter-evans/create-pull-request@v5
48+
with:
49+
commit-message: "style: format and lint code with Ruff"
50+
title: "style: format and lint code with Ruff"
51+
body: |
52+
Auto-formatted and linted code with Ruff.
53+
54+
This PR was automatically created by the Ruff GitHub Action.
55+
- Formatted code with `ruff format`
56+
- Fixed auto-fixable lint issues with `ruff check --fix`
57+
branch: format-code-with-ruff
58+
base: dev
59+
delete-branch: true
60+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
uv venv .venv
2525
source .venv/bin/activate
2626
uv pip install --upgrade pip
27-
uv pip install pytest pytest-cov opencv-python numpy
27+
uv pip install pytest opencv-python numpy
2828
uv pip install -e .
2929
3030
- name: Run tests

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ instance/
6565

6666
# Sphinx documentation
6767
docs/_build/
68+
docs/bbox_visualizer.rst
69+
docs/modules.rst
6870

6971
# PyBuilder
7072
target/

CONTRIBUTING.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ Ready to contribute? Here's how to set up `bbox_visualizer` for local developmen
7676

7777
7. Format and lint your code:
7878
```bash
79-
# Format with black
80-
uv pip run black .
79+
# Format with ruff
80+
uv run ruff format .
8181
8282
# Run linting checks with ruff
83-
uv pip run ruff check .
83+
uv run ruff check .
8484
8585
# Auto-fix ruff issues where possible
86-
uv pip run ruff check --fix .
86+
uv run ruff check --fix .
8787
8888
# Run tests
89-
uv pip run pytest
89+
uv run pytest
9090
```
9191

9292
8. Commit your changes and push your branch to GitHub:
@@ -107,15 +107,14 @@ Before you submit a pull request, check that it meets these guidelines:
107107
* Add your new functionality into a function with a docstring
108108
* Update the README.md with any new usage instructions
109109
3. The pull request should work for Python 3.8 and above.
110-
4. Make sure all tests pass and the code is formatted with black and passes ruff checks.
110+
4. Make sure all tests pass and the code is formatted and linted with ruff.
111111

112112
## Development Tools
113113

114114
This project uses modern Python development tools:
115115

116116
* **uv**: Fast Python package installer and resolver
117-
* **black**: Code formatter
118-
* **ruff**: Fast Python linter
117+
* **ruff**: Fast Python linter and formatter
119118
* **pytest**: Testing framework
120119

121120
All development dependencies are specified in the `pyproject.toml` file and will be installed when you install the package with the `[dev]` extra.

Makefile

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean clean-test clean-pyc clean-build docs help
1+
.PHONY: clean clean-test clean-pyc clean-build clean-docs docs help
22
.DEFAULT_GOAL := help
33

44
define BROWSER_PYSCRIPT
@@ -26,7 +26,7 @@ BROWSER := python -c "$$BROWSER_PYSCRIPT"
2626
help:
2727
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
2828

29-
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
29+
clean: clean-build clean-pyc clean-test clean-docs ## remove all build, test, coverage and Python artifacts
3030

3131
clean-build: ## remove build artifacts
3232
rm -fr build/
@@ -47,21 +47,25 @@ clean-test: ## remove test and coverage artifacts
4747
rm -fr htmlcov/
4848
rm -fr .pytest_cache
4949

50-
lint: ## check style with ruff
51-
uv pip run ruff check bbox_visualizer demo tests examples
50+
clean-docs: ## remove documentation build artifacts
51+
rm -fr docs/_build/
52+
rm -f docs/bbox_visualizer.rst
53+
rm -f docs/modules.rst
54+
55+
lint: ## check style and lint with ruff
56+
uv run ruff check bbox_visualizer tests examples
5257

53-
format: ## format code with black
54-
uv pip run black bbox_visualizer demo tests examples
58+
format: ## format code with ruff
59+
uv run ruff format bbox_visualizer tests examples
5560

5661
test: ## run tests with pytest
57-
uv pip run pytest
62+
uv pip install pytest
63+
uv run pytest
5864

5965
docs: ## generate Sphinx HTML documentation, including API docs
6066
rm -f docs/bbox_visualizer.rst
6167
rm -f docs/modules.rst
6268
sphinx-apidoc -o docs/ bbox_visualizer
63-
rm -f docs/bbox_visualizer.rst
64-
rm -f docs/modules.rst
6569
$(MAKE) -C docs clean
6670
$(MAKE) -C docs html
6771
$(BROWSER) docs/_build/html/index.html
@@ -70,14 +74,29 @@ servedocs: docs ## compile the docs watching for changes
7074
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .
7175

7276
build: clean ## builds source and wheel package
73-
uv pip run python -m build
77+
uv pip install build
78+
uv run python -m build
7479

7580
release: build ## package and upload a release
76-
uv pip run python -m twine check dist/*
77-
uv pip run python -m twine upload dist/*
81+
uv pip install twine
82+
uv run python -m twine check dist/*
83+
uv run python -m twine upload dist/*
7884

7985
install: clean ## install the package to the active Python's site-packages
8086
uv pip install .
8187

8288
dev-install: clean ## install the package in development mode with all extras
8389
uv pip install -e ".[dev]"
90+
91+
bump-version: ## Bump version in both files (Usage: make bump-version NEW_VERSION=0.2.1)
92+
@if [ "$(NEW_VERSION)" = "" ]; then \
93+
echo "Please provide NEW_VERSION (e.g. make bump-version NEW_VERSION=0.2.1)"; \
94+
exit 1; \
95+
fi
96+
sed -i '' 's/version = "[0-9.]*"/version = "$(NEW_VERSION)"/' pyproject.toml
97+
sed -i '' 's/__version__ = "[0-9.]*"/__version__ = "$(NEW_VERSION)"/' bbox_visualizer/_version.py
98+
git add pyproject.toml bbox_visualizer/_version.py
99+
git commit -m "Bump version to $(NEW_VERSION)"
100+
git tag v$(NEW_VERSION)
101+
git push origin v$(NEW_VERSION)
102+
git push origin

bbox_visualizer/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
from ._version import __version__
44
from .core import (
5-
draw_rectangle,
6-
draw_multiple_rectangles,
75
add_label,
86
add_multiple_labels,
9-
add_T_label,
107
add_multiple_T_labels,
8+
add_T_label,
119
draw_flag_with_label,
1210
draw_multiple_flags_with_labels,
11+
draw_multiple_rectangles,
12+
draw_rectangle,
1313
)
1414

1515
__all__ = [
1616
"__version__",
17-
"draw_rectangle",
18-
"draw_multiple_rectangles",
19-
"add_label",
20-
"add_multiple_labels",
2117
"add_T_label",
18+
"add_label",
2219
"add_multiple_T_labels",
20+
"add_multiple_labels",
2321
"draw_flag_with_label",
2422
"draw_multiple_flags_with_labels",
23+
"draw_multiple_rectangles",
24+
"draw_rectangle",
2525
]
2626

2727
__author__ = """Shoumik Sharar Chowdhury"""

bbox_visualizer/core/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
"""Core functionality for bbox-visualizer."""
22

3-
from .rectangle import draw_rectangle, draw_multiple_rectangles
4-
from .labels import add_label, add_multiple_labels
53
from .flags import (
6-
add_T_label,
74
add_multiple_T_labels,
5+
add_T_label,
86
draw_flag_with_label,
97
draw_multiple_flags_with_labels,
108
)
9+
from .labels import add_label, add_multiple_labels
10+
from .rectangle import draw_multiple_rectangles, draw_rectangle
1111

1212
__all__ = [
13-
"draw_rectangle",
14-
"draw_multiple_rectangles",
15-
"add_label",
16-
"add_multiple_labels",
1713
"add_T_label",
14+
"add_label",
1815
"add_multiple_T_labels",
16+
"add_multiple_labels",
1917
"draw_flag_with_label",
2018
"draw_multiple_flags_with_labels",
19+
"draw_multiple_rectangles",
20+
"draw_rectangle",
2121
]

bbox_visualizer/core/_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List, Tuple
44

55

6-
def validate_bbox(bbox: List[int]) -> None:
6+
def _validate_bbox(bbox: List[int]) -> None:
77
"""Validate bounding box format and values.
88
99
Args:
@@ -24,7 +24,7 @@ def validate_bbox(bbox: List[int]) -> None:
2424
)
2525

2626

27-
def validate_color(color: Tuple[int, int, int]) -> None:
27+
def _validate_color(color: Tuple[int, int, int]) -> None:
2828
"""Validate BGR color values.
2929
3030
Args:
@@ -56,7 +56,7 @@ def _check_and_modify_bbox(
5656
Returns:
5757
Adjusted bounding box coordinates [x_min, y_min, x_max, y_max]
5858
"""
59-
validate_bbox(bbox)
59+
_validate_bbox(bbox)
6060
bbox = [value if value > 0 else margin for value in bbox]
6161
bbox[2] = bbox[2] if bbox[2] < img_size[1] else img_size[1] - margin
6262
bbox[3] = bbox[3] if bbox[3] < img_size[0] else img_size[0] - margin

0 commit comments

Comments
 (0)