4.6 KiB
4.6 KiB
Contributing to FastAPI Route Loader
Thank you for your interest in contributing to fastapi-route-loader! This document provides guidelines and instructions for contributing.
Development Setup
-
Clone the repository
git clone https://github.com/yourusername/fastapi-route-loader.git cd fastapi-route-loader -
Set up the development environment
# Run the setup script bash scripts/setup.sh # Or manually: python3 -m venv .venv source .venv/bin/activate pip install -e ".[dev]" -
Verify the setup
bash scripts/verify.sh
Development Workflow
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=fastapi_route_loader --cov-report=html
# Run specific test file
pytest tests/test_container.py
# Run specific test
pytest tests/test_container.py::TestRouterContainer::test_add_router
Code Quality
We use strict linting and type checking:
# Run ruff linter
ruff check .
# Auto-fix issues
ruff check --fix .
# Format code
ruff format .
# Run type checker
pyright
Code Style Guidelines
- Type Hints: All functions must have complete type hints
- Docstrings: All public functions and classes must have docstrings
- Line Length: Maximum 88 characters (enforced by ruff)
- Imports: Use absolute imports, organized by ruff
- Python Version: Code must be compatible with Python 3.10+
Commit Messages
Follow conventional commit format:
<type>(<scope>): <subject>
<body>
<footer>
Types:
feat: New featurefix: Bug fixdocs: Documentation changestest: Test changesrefactor: Code refactoringstyle: Code style changeschore: Build/tooling changes
Example:
feat(container): add support for router priorities
Add ability to set priority levels for routers to control
loading order.
Closes #123
Pull Request Process
-
Create a feature branch
git checkout -b feature/your-feature-name -
Make your changes
- Write tests for new functionality
- Update documentation as needed
- Ensure all tests pass
- Ensure code passes linting and type checking
-
Run verification
bash scripts/verify.sh -
Commit your changes
git add . git commit -m "feat: your feature description" -
Push to your fork
git push origin feature/your-feature-name -
Create a Pull Request
- Provide a clear description of the changes
- Reference any related issues
- Ensure CI checks pass
Testing Guidelines
Writing Tests
- Place tests in the
tests/directory - Name test files as
test_*.py - Use descriptive test names:
test_<functionality>_<scenario> - Group related tests in classes
- Use fixtures for common setup
Example:
class TestRouterContainer:
def test_add_router_success(self):
container = RouterContainer()
router = APIRouter()
container.add_router("test", router)
assert container.has_router("test")
def test_add_router_duplicate_raises_error(self):
container = RouterContainer()
router = APIRouter()
container.add_router("test", router)
with pytest.raises(ValueError):
container.add_router("test", router)
Test Coverage
- Aim for >90% code coverage
- Test both success and error cases
- Test edge cases and boundary conditions
- Test integration scenarios
Documentation
Docstring Format
Use Google-style docstrings:
def add_router(self, name: str, router: APIRouter, metadata: dict[str, Any] | None = None) -> None:
"""Add a router to the container.
Args:
name: Unique name for the router
router: APIRouter instance
metadata: Optional metadata for the event
Raises:
ValueError: If router name already exists
Example:
>>> container = RouterContainer()
>>> router = APIRouter()
>>> container.add_router("users", router)
"""
Updating Documentation
- Update README.md for user-facing changes
- Update docstrings for API changes
- Add examples for new features
- Update CHANGELOG.md
Release Process
- Update version in
pyproject.toml - Update CHANGELOG.md
- Create a git tag:
git tag v0.1.0 - Push tag:
git push origin v0.1.0 - Create GitHub release
- Publish to PyPI (maintainers only)
Questions?
Feel free to open an issue for:
- Bug reports
- Feature requests
- Questions about contributing
- General discussion
Thank you for contributing! 🎉