This file contains guidelines and instructions for agentic coding agents working in this repository.
Robotoff is a real-time and batch prediction service for Open Food Facts. It's a Python project (Python 3.11+) using Falcon for APIs, Peewee for database, and various ML libraries.
# Run all tests (unit + integration)
make tests
# Run only unit tests
make unit-tests
# Run only integration tests
make integration-tests
# Run ML tests (requires Triton server)
make ml-tests
# Run a specific test file or function (most common)
make pytest args='tests/unit/path/to/test_file.py::test_function_name'
# Run a specific test file
make pytest args='tests/unit/path/to/test_file.py'
# Run with pytest options (e.g., --pdb for debugging)
make pytest args='tests/unit/path/to/test_file.py::test_function_name --pdb'# Run all checks (toml, ruff, mypy, docs)
make checks
# Run individual linters
make ruff-format # auto-format code
make ruff-check # lint code
make mypy # type checking
# Run all linter + formatter
make lintmake dev # Setup development environment
make up # Start containers
make down # Stop containers
make tests args='...' # Run specific pytest args- Line length: 88 characters (matches Black default)
- Formatter: Ruff
Run make lint to auto-format code.
- Linter: ruff
- Max line length: 88
- Ignored rules: E203 (whitespace before ':'), E501 (line too long), W503 (line break before binary operator)
- Max doc length: 88
- Type checker: mypy (v1.10.1)
- Config:
ignore_missing_imports = truein pyproject.toml - This project uses Python type hints extensively, especially with Pydantic models
# Standard library first
import dataclasses
import datetime
import enum
from collections import Counter
from typing import Any, Literal, Self
# Third-party libraries
from pydantic import BaseModel, ConfigDict, model_validator
import requests
# Local application imports
from robotoff import settings
from robotoff.types import JSONType
from robotoff.utils import some_function- Classes: PascalCase (e.g.,
ObjectDetectionModel,InsightType) - Functions/variables: snake_case (e.g.,
get_image_from_url,jsonl_iter) - Constants: SCREAMING_SNAKE_CASE (e.g.,
DEFAULT_TIMEOUT) - Enums: Use
@enum.uniquedecorator for enum classes - Types: Use type hints for all function arguments and return values
from pydantic import BaseModel, ConfigDict, model_validator
class MyModel(BaseModel):
model_config = ConfigDict(...)
name: str
value: int
@model_validator(mode='before')
@classmethod
def validate_values(cls, data: Any) -> Any:
# validation logic
return data- Use custom exceptions with clear names
- Use
from robotoff.exceptions import ...pattern for custom errors - Use
orjsonfor JSON operations (faster than standard json) - Use
backofffor retry logic with exponential backoff
- Uses Peewee ORM (
peewee~=3.17.6) - Models defined in
robotoff/models.py - Migrations managed via
peewee-migrate
- Tests in
tests/unit/,tests/integration/,tests/ml/ - Use
pytestwithpytest-mockandpytest-httpserver - Use
requests-mockfor HTTP mocking - Test files:
test_*.pyor*_test.py
The project uses Ruff as a formatter, linter and import sorter.
Install hooks with: pre-commit install
- Uses Falcon (
falcon~=3.1.3) for REST APIs - Follows Falcon resource/responder patterns
- API docs: Spectral OpenAPI linting in
docs/references/api.yml - Docs built with MkDocs Material
pyproject.toml: Project configuration and dependenciesMakefile: Development commands.pre-commit-config.yaml: Pre-commit hooksrobotoff/settings.py: Application settings
- This project requires Python 3.11+
- Uses
uvfor dependency management in Docker - Docker-based development environment (see docker-compose.yml)
- Integrates with PostgreSQL, Elasticsearch, Redis, and Triton (ML inference)