Skip to content

Dev #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 16, 2025
Merged

Dev #38

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions .github/workflows/black.yml

This file was deleted.

60 changes: 60 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Ruff

on: [push, pull_request]

permissions:
contents: write
pull-requests: write

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install Ruff
run: pip install ruff

- name: Run Ruff Format Check
id: ruff-format
continue-on-error: true
run: |
ruff format --check bbox_visualizer tests examples
echo "format_changes=$?" >> $GITHUB_OUTPUT

- name: Run Ruff Lint Check
id: ruff-lint
continue-on-error: true
run: |
ruff check bbox_visualizer tests examples
echo "lint_changes=$?" >> $GITHUB_OUTPUT

- name: Format and Fix with Ruff if needed
if: steps.ruff-format.outputs.format_changes == '1' || steps.ruff-lint.outputs.lint_changes == '1'
run: |
ruff format bbox_visualizer tests examples
ruff check --fix bbox_visualizer tests examples

- name: Create Pull Request
if: steps.ruff-format.outputs.format_changes == '1' || steps.ruff-lint.outputs.lint_changes == '1'
uses: peter-evans/create-pull-request@v5
with:
commit-message: "style: format and lint code with Ruff"
title: "style: format and lint code with Ruff"
body: |
Auto-formatted and linted code with Ruff.

This PR was automatically created by the Ruff GitHub Action.
- Formatted code with `ruff format`
- Fixed auto-fixable lint issues with `ruff check --fix`
branch: format-code-with-ruff
base: dev
delete-branch: true
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uv venv .venv
source .venv/bin/activate
uv pip install --upgrade pip
uv pip install pytest pytest-cov opencv-python numpy
uv pip install pytest opencv-python numpy
uv pip install -e .

- name: Run tests
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ instance/

# Sphinx documentation
docs/_build/
docs/bbox_visualizer.rst
docs/modules.rst

# PyBuilder
target/
Expand Down
15 changes: 7 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ Ready to contribute? Here's how to set up `bbox_visualizer` for local developmen

7. Format and lint your code:
```bash
# Format with black
uv pip run black .
# Format with ruff
uv run ruff format .

# Run linting checks with ruff
uv pip run ruff check .
uv run ruff check .

# Auto-fix ruff issues where possible
uv pip run ruff check --fix .
uv run ruff check --fix .

# Run tests
uv pip run pytest
uv run pytest
```

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

## Development Tools

This project uses modern Python development tools:

* **uv**: Fast Python package installer and resolver
* **black**: Code formatter
* **ruff**: Fast Python linter
* **ruff**: Fast Python linter and formatter
* **pytest**: Testing framework

All development dependencies are specified in the `pyproject.toml` file and will be installed when you install the package with the `[dev]` extra.
43 changes: 31 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean clean-test clean-pyc clean-build docs help
.PHONY: clean clean-test clean-pyc clean-build clean-docs docs help
.DEFAULT_GOAL := help

define BROWSER_PYSCRIPT
Expand Down Expand Up @@ -26,7 +26,7 @@ BROWSER := python -c "$$BROWSER_PYSCRIPT"
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

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

clean-build: ## remove build artifacts
rm -fr build/
Expand All @@ -47,21 +47,25 @@ clean-test: ## remove test and coverage artifacts
rm -fr htmlcov/
rm -fr .pytest_cache

lint: ## check style with ruff
uv pip run ruff check bbox_visualizer demo tests examples
clean-docs: ## remove documentation build artifacts
rm -fr docs/_build/
rm -f docs/bbox_visualizer.rst
rm -f docs/modules.rst

lint: ## check style and lint with ruff
uv run ruff check bbox_visualizer tests examples

format: ## format code with black
uv pip run black bbox_visualizer demo tests examples
format: ## format code with ruff
uv run ruff format bbox_visualizer tests examples

test: ## run tests with pytest
uv pip run pytest
uv pip install pytest
uv run pytest

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

build: clean ## builds source and wheel package
uv pip run python -m build
uv pip install build
uv run python -m build

release: build ## package and upload a release
uv pip run python -m twine check dist/*
uv pip run python -m twine upload dist/*
uv pip install twine
uv run python -m twine check dist/*
uv run python -m twine upload dist/*

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

dev-install: clean ## install the package in development mode with all extras
uv pip install -e ".[dev]"

bump-version: ## Bump version in both files (Usage: make bump-version NEW_VERSION=0.2.1)
@if [ "$(NEW_VERSION)" = "" ]; then \
echo "Please provide NEW_VERSION (e.g. make bump-version NEW_VERSION=0.2.1)"; \
exit 1; \
fi
sed -i '' 's/version = "[0-9.]*"/version = "$(NEW_VERSION)"/' pyproject.toml
sed -i '' 's/__version__ = "[0-9.]*"/__version__ = "$(NEW_VERSION)"/' bbox_visualizer/_version.py
git add pyproject.toml bbox_visualizer/_version.py
git commit -m "Bump version to $(NEW_VERSION)"
git tag v$(NEW_VERSION)
git push origin v$(NEW_VERSION)
git push origin
14 changes: 7 additions & 7 deletions bbox_visualizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

from ._version import __version__
from .core import (
draw_rectangle,
draw_multiple_rectangles,
add_label,
add_multiple_labels,
add_T_label,
add_multiple_T_labels,
add_T_label,
draw_flag_with_label,
draw_multiple_flags_with_labels,
draw_multiple_rectangles,
draw_rectangle,
)

__all__ = [
"__version__",
"draw_rectangle",
"draw_multiple_rectangles",
"add_label",
"add_multiple_labels",
"add_T_label",
"add_label",
"add_multiple_T_labels",
"add_multiple_labels",
"draw_flag_with_label",
"draw_multiple_flags_with_labels",
"draw_multiple_rectangles",
"draw_rectangle",
]

__author__ = """Shoumik Sharar Chowdhury"""
Expand Down
14 changes: 7 additions & 7 deletions bbox_visualizer/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""Core functionality for bbox-visualizer."""

from .rectangle import draw_rectangle, draw_multiple_rectangles
from .labels import add_label, add_multiple_labels
from .flags import (
add_T_label,
add_multiple_T_labels,
add_T_label,
draw_flag_with_label,
draw_multiple_flags_with_labels,
)
from .labels import add_label, add_multiple_labels
from .rectangle import draw_multiple_rectangles, draw_rectangle

__all__ = [
"draw_rectangle",
"draw_multiple_rectangles",
"add_label",
"add_multiple_labels",
"add_T_label",
"add_label",
"add_multiple_T_labels",
"add_multiple_labels",
"draw_flag_with_label",
"draw_multiple_flags_with_labels",
"draw_multiple_rectangles",
"draw_rectangle",
]
6 changes: 3 additions & 3 deletions bbox_visualizer/core/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import List, Tuple


def validate_bbox(bbox: List[int]) -> None:
def _validate_bbox(bbox: List[int]) -> None:
"""Validate bounding box format and values.

Args:
Expand All @@ -24,7 +24,7 @@ def validate_bbox(bbox: List[int]) -> None:
)


def validate_color(color: Tuple[int, int, int]) -> None:
def _validate_color(color: Tuple[int, int, int]) -> None:
"""Validate BGR color values.

Args:
Expand Down Expand Up @@ -56,7 +56,7 @@ def _check_and_modify_bbox(
Returns:
Adjusted bounding box coordinates [x_min, y_min, x_max, y_max]
"""
validate_bbox(bbox)
_validate_bbox(bbox)
bbox = [value if value > 0 else margin for value in bbox]
bbox[2] = bbox[2] if bbox[2] < img_size[1] else img_size[1] - margin
bbox[3] = bbox[3] if bbox[3] < img_size[0] else img_size[0] - margin
Expand Down
Loading