This guide covers setting up the development environment and using the code quality tools.
# Clone the repository
git clone <repository-url>
cd trackstudio
# Set up development environment
make dev-setup
# Run a quick check
make dev-check- Python 3.10+
- uv (recommended) or pip
# Install with uv (recommended)
make install-dev
# Or manually with uv
uv sync --all-extras --devWe use Ruff for both linting and code formatting, replacing Black, isort, flake8, and more.
# Run linter
make lint
# Format code
make format
# Check formatting without making changes
make format-check
# Fix auto-fixable issues
make fix# Run type checking
make type-check# Run security linter
make security# Run all code quality checks
make check-all
# Run the full CI pipeline locally
make ciRuff is configured in pyproject.toml:
[tool.ruff]
line-length = 120
target-version = "py310"
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"N", # pep8-naming
"UP", # pyupgrade
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"SIM", # flake8-simplify
"RET", # flake8-return
"ARG", # flake8-unused-arguments
"PTH", # flake8-use-pathlib
"ERA", # eradicate (commented code)
"PL", # pylint
"PERF", # perflint
]Pre-commit hooks automatically run code quality checks on commit:
# Install pre-commit hooks
make pre-commit-install
# Run pre-commit on all files manually
make pre-commit-runCode quality checks run automatically on:
- Push to
mainordevelopbranches - Pull requests to
mainordevelopbranches
The CI pipeline includes:
- Linting with Ruff
- Formatting checks with Ruff
- Type checking with MyPy
- Security scanning with Bandit
- Testing multiple Python versions (3.10, 3.11, 3.12)
| Command | Description |
|---|---|
make help |
Show all available commands |
make dev-setup |
Complete development setup |
make dev-check |
Quick development check (fix + check all) |
make fix |
Auto-fix linting and formatting issues |
make check-all |
Run all quality checks |
make ci |
Run full CI pipeline locally |
make run-server |
Start TrackStudio server |
If Ruff finds issues:
- Auto-fixable issues: Run
make fix - Manual fixes needed: Check the error messages and fix manually
- Configuration: Adjust rules in
pyproject.tomlif needed
Common MyPy issues:
- Missing imports: Add
# type: ignorefor third-party libraries - Type annotations: Add proper type hints to functions
- Optional types: Use
X | Noneinstead ofOptional[X](Python 3.10+)
If pre-commit hooks fail:
- Fix the issues reported
- Stage the fixes:
git add . - Commit again
# Standard library
import os
import sys
# Third-party
import numpy as np
import torch
# Local imports
from trackstudio.core import VisionAPI
from .base import BaseTracker# Use modern union syntax (Python 3.10+)
def process_frame(frame: np.ndarray | None) -> list[Detection]:
...
# Avoid old-style typing
# from typing import Optional, List # ❌
# def process_frame(frame: Optional[np.ndarray]) -> List[Detection]: # ❌def track_objects(frame: np.ndarray, detections: list[Detection]) -> list[Track]:
"""
Track objects across frames.
Args:
frame: Input image frame
detections: List of detected objects
Returns:
List of tracked objects with IDs
Raises:
ValueError: If frame is empty
"""The GitHub Actions workflow will show status badges for:
- ✅ Linting passed
- ✅ Formatting passed
- ✅ Type checking passed
- ✅ Security scan passed
- ✅ Tests passed
Before submitting a PR:
- Run
make dev-checkto ensure code quality - Add tests for new functionality
- Update documentation as needed
- Ensure all CI checks pass