1+ ---
2+ description:
3+ globs:
4+ alwaysApply: true
5+ ---
6+ # Coding Standards & Best Practices
7+
8+ This document outlines the core coding standards, best practices, and quality control procedures for the codebase.
9+
10+ ## Type Hints
11+
12+ 1. **Always Use Type Hints**
13+ - Every function parameter must be typed
14+ - Every function return must be typed
15+ - Use type hints for all variables where type is not obvious
16+ - Use types with Uppercase first letter (Dict[], List[], etc.)
17+
18+ 2. **StrEnum**
19+ - Import from `pipelex.types`:
20+ ```python
21+ from pipelex.types import StrEnum
22+ ```
23+
24+ ## BaseModel Standards
25+
26+ - Respect Pydantic v2 standards
27+ - Keep models focused and single-purpose
28+ - Use descriptive field names
29+ - Use type hints for all fields
30+ - Document complex validations
31+ - Use Optional[] for nullable fields
32+ - Use Field(default_factory=...) for mutable defaults
33+
34+ ## Factory Pattern
35+
36+ - Use Factory Pattern for object creation when dealing with multiple implementations
37+
38+ ## Documentation
39+
40+ 1. **Docstring Format**
41+ ```python
42+ def process_image(image_path: str, size: Tuple[int, int]) -> bytes:
43+ """Process and resize an image.
44+
45+ Args:
46+ image_path: Path to the source image
47+ size: Tuple of (width, height) for resizing
48+
49+ Returns:
50+ Processed image as bytes
51+ """
52+ pass
53+ ```
54+
55+ 2. **Class Documentation**
56+ ```python
57+ class ImageProcessor:
58+ """Handles image processing operations.
59+
60+ Provides methods for resizing, converting, and optimizing images.
61+ """
62+ ```
63+
64+ ## Error Handling
65+
66+ 1. **Graceful Error Handling**
67+ - Use try/except blocks with specific exceptions
68+ - Convert third-party exceptions to custom ones
69+ ```python
70+ try:
71+ from fal_client import AsyncClient as FalAsyncClient
72+ except ImportError as exc:
73+ raise MissingDependencyError(
74+ "fal-client", "fal",
75+ "The fal-client SDK is required to use FAL models."
76+ ) from exc
77+ ```
78+
79+ ## Code Quality Checks
80+
81+ ### Linting and Type Checking
82+
83+ Before finalizing a task, run:
84+ ```bash
85+ make fix-unused-imports
86+ make check
87+ ```
88+
89+ This runs multiple code quality tools:
90+ - Pyright: Static type checking
91+ - Ruff: Fast Python linter
92+ - Mypy: Static type checker
93+
94+ Always fix any issues reported by these tools before proceeding.
95+
96+ ### Running Tests
97+
98+ 1. **Quick Test Run** (no LLM/image generation):
99+ ```bash
100+ make tp
101+ ```
102+ Runs tests with markers: `(dry_runnable or not (inference or llm or imgg or ocr)) and not (needs_output or pipelex_api)`
103+
104+ 2. **Specific Tests**:
105+ ```bash
106+ make tp TEST=TestClassName
107+ # or
108+ make tp TEST=test_function_name
109+ ```
110+ Note: Matches names starting with the provided string.
111+
112+ **Important**: Never run `make ti`, `make test-inference`, `make to`, `make test-ocr`, `make tg`, or `make test-imgg` - these use costly inference.
113+
114+ ## Pipelines
115+
116+ - All pipeline definitions go in `pipelex/libraries/pipelines/`
117+ - Always validate pipelines after creation/edit with `make validate`.
118+ Iterate if there are errors.
119+
120+ ## Project Structure
121+
122+ - **Pipelines**: `pipelex/libraries/pipelines/`
123+ - **Tests**: `tests/` directory
124+ - **Documentation**: `docs/` directory
0 commit comments