|
| 1 | +<!-- SPDX-FileCopyrightText: 2025 Alexandre Gomes Gaigalas <alganet@gmail.com> --> |
| 2 | +<!-- SPDX-License-Identifier: ISC --> |
| 3 | + |
| 4 | +# AI Coding Guidelines for apywire |
| 5 | + |
| 6 | +## Overview |
| 7 | +apywire is a Python library for object wiring with lazy loading. It provides dependency injection through spec-based configuration and code generation. |
| 8 | + |
| 9 | +## Architecture |
| 10 | +- **Core Components**: `Wired` class (lazy container), `wire()` (factory), `compile()` (code generator) |
| 11 | +- **Data Flow**: Spec dict → `_parse_spec()` → ParsedSpec → `Wired.__init__()` → lazy `__getattr__()` → instantiate with `**value` |
| 12 | +- **Key Patterns**: Generic with `TypeVar T` for value types, lazy loading via `__getattr__`, spec parsing with module/class resolution |
| 13 | +- **Equivalence Goal**: `compile()` and `wire()` produce equivalent behavior - compiled code should match wired object functionality |
| 14 | +- **Config-Friendly Specs**: Specs are designed to be easily serializable from YAML/JSON |
| 15 | + |
| 16 | +## Developer Workflows |
| 17 | +- **Full Check**: `make all` (format, lint, test coverage) |
| 18 | +- **Build & Publish**: `make build` (creates dist/), `make publish` (uploads to PyPI) |
| 19 | +- **Clean**: `make clean` (removes __pycache__, .coverage, etc.) |
| 20 | +- **Debug**: Use `pytest -xvs` for verbose test runs |
| 21 | + |
| 22 | +## Conventions |
| 23 | +- **Typing**: Strict mypy with `disallow_any_* = true`, use `object` over `Any` |
| 24 | +- **Formatting**: 79 char lines with black/isort |
| 25 | +- **Licensing**: SPDX headers on all files, REUSE compliance |
| 26 | +- **Coverage**: 95% required, test edge cases like `AttributeError` in `__getattr__` |
| 27 | +- **Structure**: Type aliases in wiring.py, Makefile-driven development |
| 28 | + |
| 29 | +## Examples |
| 30 | +- **Lazy Access**: `wired = wire(spec); obj = wired.someName` (instantiates on first access) |
| 31 | +- **Spec Format**: `{"module.Class name": {"param": "value"}}` (YAML/JSON-compatible structure) |
| 32 | +- **Generic Usage**: Functions use `[T]` for type safety without runtime generics |
| 33 | +- **Equivalence**: `compile(spec)` generates code that behaves identically to `wire(spec)` |
| 34 | + |
| 35 | +## Key Files |
| 36 | +- `apywire/wiring.py`: Core implementation |
| 37 | +- `Makefile`: All dev commands |
| 38 | +- `pyproject.toml`: Dependencies and config |
| 39 | +- `tests/test_simple.py`: Usage examples |
0 commit comments