Code Style¶
dppvalidator follows consistent coding standards enforced by automated tools.
Tools¶
- Ruff — Linting and formatting
- ty — Type checking
Running Checks¶
# Lint check
uv run ruff check .
# Format check
uv run ruff format --check .
# Type check
uv run ty check src/
Auto-fix¶
Style Guidelines¶
Imports¶
- Group imports: stdlib, third-party, local
- Use absolute imports
- Sort alphabetically within groups
from __future__ import annotations
import json
from pathlib import Path
from pydantic import BaseModel
from dppvalidator.logging import get_logger
Type Hints¶
- Type hint all public functions
- Use
from __future__ import annotationsfor forward references - Use
typing.TYPE_CHECKINGfor import-only types
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from dppvalidator.models import DigitalProductPassport
def validate(passport: DigitalProductPassport) -> bool: ...
Docstrings¶
Use Google-style docstrings:
def validate(data: dict) -> ValidationResult:
"""Validate a Digital Product Passport.
Args:
data: The passport data as a dictionary.
Returns:
A ValidationResult with errors and warnings.
Raises:
ValueError: If data is not a valid dictionary.
"""
Line Length¶
Maximum 100 characters per line.
Naming Conventions¶
snake_casefor functions, variables, modulesPascalCasefor classesUPPER_CASEfor constants
Pre-commit¶
Pre-commit hooks run automatically on commit:
Next Steps¶
- Testing — Writing tests
- Development Setup — Environment setup