Skip to content

Commit ded3e24

Browse files
authored
Merge pull request #48 from thecodecrate/refactor/simplify
docs: remove note about the code structure
2 parents c31134b + 931c1df commit ded3e24

File tree

8 files changed

+164
-25
lines changed

8 files changed

+164
-25
lines changed

.github/workflows/format-ruff.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
persist-credentials: false
2222

2323
- name: Install uv
24-
uses: astral-sh/setup-uv@v4
24+
uses: astral-sh/setup-uv@e4db8464a088ece1b920f60402e813ea4de65b8f # v4
2525
with:
2626
github-token: ${{ secrets.GITHUB_TOKEN }}
2727
enable-cache: true
@@ -31,4 +31,4 @@ jobs:
3131
run: uvx ruff format .
3232

3333
- name: Commit changes
34-
uses: stefanzweifel/git-auto-commit-action@v5
34+
uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5

.github/workflows/lint-ruff.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
persist-credentials: false
2222

2323
- name: Install uv
24-
uses: astral-sh/setup-uv@v4
24+
uses: astral-sh/setup-uv@e4db8464a088ece1b920f60402e813ea4de65b8f # v4
2525
with:
2626
github-token: ${{ secrets.GITHUB_TOKEN }}
2727
enable-cache: true

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
persist-credentials: false
2020

2121
- name: Install uv
22-
uses: astral-sh/setup-uv@v4
22+
uses: astral-sh/setup-uv@e4db8464a088ece1b920f60402e813ea4de65b8f # v4
2323
with:
2424
github-token: ${{ secrets.GITHUB_TOKEN }}
25-
enable-cache: true
25+
enable-cache: false
2626
cache-dependency-glob: uv.lock
2727

2828
- name: Set up Python

.github/workflows/security-zizmor.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
persist-credentials: false
2626

2727
- name: Install uv
28-
uses: astral-sh/setup-uv@v4
28+
uses: astral-sh/setup-uv@e4db8464a088ece1b920f60402e813ea4de65b8f # v4
2929
with:
3030
github-token: ${{ secrets.GITHUB_TOKEN }}
3131
enable-cache: true

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
persist-credentials: false
2929

3030
- name: Install uv
31-
uses: astral-sh/setup-uv@v4
31+
uses: astral-sh/setup-uv@e4db8464a088ece1b920f60402e813ea4de65b8f # v4
3232
with:
3333
github-token: ${{ secrets.GITHUB_TOKEN }}
3434
enable-cache: true

CLAUDE.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a Python implementation of the Pipeline pattern, distributed as `thecodecrate-pipeline`. The package allows composing sequential stages into reusable, immutable pipelines for processing data. It's inspired by the PHP League Pipeline package.
8+
9+
## Development Commands
10+
11+
### Environment Setup
12+
```bash
13+
# The project uses uv for dependency management
14+
# Dependencies are managed in pyproject.toml under [dependency-groups]
15+
uv sync
16+
```
17+
18+
### Testing
19+
```bash
20+
# Run all tests
21+
pytest
22+
23+
# Run tests with coverage
24+
pytest --cov
25+
26+
# Run a specific test file
27+
pytest tests/test_pipeline.py
28+
29+
# Run a specific test function
30+
pytest tests/test_pipeline.py::test_function_name
31+
```
32+
33+
### Code Quality
34+
```bash
35+
# Format code with ruff
36+
ruff format .
37+
38+
# Lint with ruff
39+
ruff check .
40+
41+
# Fix auto-fixable linting issues
42+
ruff check --fix .
43+
44+
# Format with black (line length: 79)
45+
black .
46+
47+
# Type checking is configured with strict mode in pyrightconfig.json
48+
# Type check manually: pyright (if installed)
49+
```
50+
51+
### Documentation
52+
```bash
53+
# Build documentation locally
54+
mkdocs serve
55+
56+
# Documentation is built with mkdocs-material and auto-generates API docs
57+
# from docstrings using mkdocstrings-python
58+
```
59+
60+
### Version Management
61+
```bash
62+
# Bump version (uses bumpver)
63+
bumpver update --patch # 1.26.0 -> 1.26.1
64+
bumpver update --minor # 1.26.0 -> 1.27.0
65+
bumpver update --major # 1.26.0 -> 2.0.0
66+
67+
# Note: bumpver automatically commits and tags, but does NOT push
68+
```
69+
70+
## Architecture
71+
72+
### Core Concepts
73+
74+
The codebase implements a pipeline pattern with three main abstractions:
75+
76+
1. **Stage**: A callable unit that transforms input to output (`StageInterface[T_in, T_out]`)
77+
2. **Pipeline**: An immutable chain of stages (`PipelineInterface[T_in, T_out]`)
78+
3. **Processor**: Controls how stages are executed (`ProcessorInterface[T_in, T_out]`)
79+
80+
### Directory Structure
81+
82+
```
83+
src/
84+
├── _lib/ # Internal implementation
85+
│ ├── pipeline/ # Core pipeline implementation
86+
│ │ ├── pipeline.py # Main Pipeline class
87+
│ │ ├── pipeline_factory.py # Factory for building pipelines
88+
│ │ ├── processor.py # Base Processor class
89+
│ │ ├── stage.py # Base Stage class
90+
│ │ ├── processors/ # Built-in processors
91+
│ │ │ ├── chained_processor.py
92+
│ │ │ └── ...
93+
│ │ └── traits/ # Mixins (Clonable, ActAsFactory)
94+
│ └── processors/ # Additional processor implementations
95+
│ ├── chained_processor/ # Processor that chains stages
96+
│ └── interruptible_processor/ # Processor with interruption support
97+
└── thecodecrate_pipeline/ # Public API package
98+
├── __init__.py # Re-exports from _lib
99+
├── processors/ # Public processor exports
100+
└── types/ # Public type exports
101+
```
102+
103+
### Key Design Patterns
104+
105+
**Immutability**: Pipelines use copy-on-write semantics. The `pipe()` method creates a new pipeline instance with the added stage, preserving the original pipeline.
106+
107+
**Traits System**: The codebase uses a trait-like pattern with mixins:
108+
- `Clonable`: Provides shallow cloning capability
109+
- `ActAsFactory`: Enables objects to act as factories for creating instances
110+
111+
**Interface Segregation**: Each core concept has an interface (`*Interface`) and implementation, enabling custom implementations while maintaining type safety.
112+
113+
**Async-First**: All processing is async (`async def process(...)`). The processor handles both sync and async callables transparently using `inspect.isawaitable()`.
114+
115+
### Type System
116+
117+
The codebase uses generic type variables for type safety:
118+
- `T_in`: Input type to a stage or pipeline
119+
- `T_out`: Output type from a stage or pipeline (defaults to `T_in`)
120+
121+
Stages can transform types:
122+
```python
123+
Pipeline[int, str] # Takes int, returns str
124+
StageInterface[int, int] # Takes int, returns int
125+
```
126+
127+
### Processing Flow
128+
129+
1. A Pipeline is created with stages (either via `.pipe()` or declaratively)
130+
2. When `.process(payload)` is called, the pipeline:
131+
- Instantiates stages if needed (converts classes to instances)
132+
- Delegates to the processor's `.process()` method
133+
- The processor iterates through stages, passing output to next stage
134+
3. Processors can customize execution (e.g., ChainedProcessor for error handling)
135+
136+
### Stream Processing
137+
138+
Pipelines support processing `AsyncIterator` streams, allowing real-time data transformation where each stage can yield results consumed immediately by the next stage.
139+
140+
### PipelineFactory
141+
142+
Because pipelines are immutable, `PipelineFactory` provides mutable stage collection during composition. It builds the final immutable pipeline via `.build()`.
143+
144+
## Testing Notes
145+
146+
- Test files use stub classes in `tests/stubs/` for consistent test fixtures
147+
- Tests are async-aware (configured via `pytest.ini` with `pytest-asyncio`)
148+
- Mock stages implement `StageInterface` for type safety
149+
150+
## Python Version
151+
152+
Requires Python 3.13+ (specified in pyproject.toml).
153+
154+
## Package Distribution
155+
156+
Built with `hatchling`. The wheel includes both `thecodecrate_pipeline` (public API) and `_api` packages (internal). The public package re-exports symbols from `_lib`.

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,3 @@ except ZeroDivisionError as e:
252252
# Handle the exception.
253253
pass
254254
```
255-
256-
## Architecture
257-
258-
All code is located in the `src/_api` directory and follows the Static-Plugin Design (SPD) pattern. This architectural approach ensures:
259-
260-
- Clear separation of concerns through static plugins
261-
- Full static analysis capabilities
262-
- Predictable code execution paths
263-
- Zero runtime overhead
264-
265-
The project utilizes class composition rather than dynamic plugins, making the codebase easier to maintain and debug while preserving extensibility.
266-
267-
### Project's Specs and Guidelines
268-
269-
- [spec2: Static-Plugin Design](https://github.com/thecodecrate/guidelines/blob/main/specs/spec-002--static-plugin-design/README.md)
270-
- [spec3: SPD Manifest Files](https://github.com/thecodecrate/guidelines/blob/main/specs/spec-003--spd-manifest-files/README.md)
271-
- [spec4: SPD Naming Convention](https://github.com/thecodecrate/guidelines/blob/main/specs/spec-004--spd-naming-convention/README.md)

tests/test_linting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_zizmor_compliance():
1818
"""Test to ensure codebase is compliant with Zizmor linting."""
1919

2020
result = subprocess.run(
21-
["uvx", "zizmor", ".github/workflows/"],
21+
["uvx", "zizmor", "--min-severity", "low", ".github/workflows/"],
2222
stdout=subprocess.PIPE,
2323
stderr=subprocess.PIPE,
2424
text=True,

0 commit comments

Comments
 (0)