This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is yamldataclassconfig, a Python library that enables type-safe importing of YAML configuration files into Python dataclasses. The library bridges YAML configuration files with Python's dataclass system, providing global config access and testability.
yamldataclassconfig/config.py: ContainsYamlDataClassConfig- the main abstract base class that users inherit from to create config classesyamldataclassconfig/utility.py: Utility functions for path handling (build_path,create_file_path_field) and dataclass metadatayamldataclassconfig/__init__.py: Package entry point that exposes all public APIs
- Delayed Loading: Config classes are instantiated globally but YAML files are loaded explicitly via
load()method to support testing - Path Resolution: Supports both relative (to current working directory) and absolute paths for config files
- Type Safety: Uses
dataclasses-jsonand marshmallow for type-safe YAML to dataclass conversion
The project uses uv as the package manager and invoke for task automation:
uv run invoke test # Run fast tests (excludes @pytest.mark.slow)
uv run invoke test.all # Run all tests including slow ones
uv run invoke test.coverage # Run tests with coverage report
uv run pytest path/to/test # Run specific test fileuv run invoke lint # Fast linting (xenon, ruff, bandit, dodgy, flake8, pydocstyle)
uv run invoke lint.deep # Slow but thorough linting (mypy, pylint, semgrep)
uv run invoke lint.mypy # Type checking only
uv run invoke lint.ruff # Ruff linting onlyuv run invoke style # Format code with docformatter and Ruff
uv run invoke style --check # Check formatting without making changesuv run invoke dist # Build source and wheel packages
uv run invoke clean.all # Clean all build artifactsyamldataclassconfig/ # Main package
├── __init__.py # Public API exports
├── config.py # YamlDataClassConfig base class
├── utility.py # Path utilities and helpers
└── py.typed # PEP 561 typing marker
tests/ # Test suite
├── conftest.py # pytest configuration
├── test_*.py # Test modules
└── testresources/ # Test fixtures and resources
docs/ # Documentation
└── CONTRIBUTING.md # Contribution guidelines
- Uses Python 3.7+ type hints throughout
- Follows dataclasses pattern with
@dataclassdecorator - Uses
dataclasses-jsonfor serialization/deserialization - Line length: 119 characters (configured for Black compatibility)
- Import style: Force single-line imports (ruff configured)
- Documentation: Google docstring style
- Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.
- Function arguments requires to have type annotations.
- Use Guard Clauses to reduce nesting and improve readability.
- ALL imports MUST be at the top-level of the file, immediately after any module comments and docstrings, and before module globals and constants
- NEVER place imports inside functions, methods, or classes - this violates PEP 8 and makes dependencies unclear
- NEVER use conditional imports inside functions unless absolutely necessary for optional dependencies
- Standard library imports
- Third-party library imports
- Local application/library imports
# ❌ NEVER DO THIS - imports inside methods
def test_something():
import os # WRONG!
from pathlib import Path # WRONG!
# ❌ NEVER DO THIS - imports inside classes
class TestClass:
def method(self):
import tempfile # WRONG!
# ✅ CORRECT - all imports at top
import os
import tempfile
from pathlib import Path
def test_something():
# Use the imports hereExceptions
- Only use local imports when dealing with circular dependencies or optional dependencies that may not be available
- If you must use local imports, document the reason with a comment
The project has comprehensive tooling configuration in pyproject.toml:
- Ruff: Linting and formatting with ALL rules enabled, specific ignores for docstring requirements
- mypy: Strict mode enabled
- pytest: Slow test markers configured
- coverage: Source tracking for
yamldataclassconfigpackage
- Auto-linting: Files are automatically linted after edits via hooks
- Permissions: Pre-configured to allow editing main package and test files
- Git operations: Commit and push operations are restricted to prevent accidental changes
- Fast tests run by default, slow tests marked with
@pytest.mark.slow - Uses fixture files for configuration testing scenarios
- Tests cover both unittest and pytest patterns for config loading
- Test resources stored in
tests/testresources/for isolation