Contributing¶
Thank you for your interest in contributing to filetype-detector.
This guide covers the development workflow, project conventions, and documentation expectations for contributors.
Development Setup¶
Prerequisites¶
- Python >= 3.10
- rye (recommended) or pip/venv
- Git
Setting Up Development Environment¶
-
Clone the repository:
-
Install dependencies:
Or with pip:
- Install system dependencies (for MagicInferencer and HybridInferencer):
Ubuntu/Debian:
Fedora/RHEL/CentOS:
Arch Linux:
macOS:
Windows:
Alpine Linux (Docker):
Verify installation:
Development Workflow¶
Running Tests¶
# Run all tests
pytest tests/ -v
# Run with logging
pytest tests/ -v -s
# Run specific test file
pytest tests/test_magic_inferencer.py -v
# Run with coverage
pytest tests/ --cov=src/filetype_detector --cov-report=html
Code Quality¶
Linting:
Type Checking:
Building Documentation¶
Coding Standards¶
Code Style¶
- Follow PEP 8
- Use type hints for all function signatures
- Docstrings in numpy-style format
- Line length: 88 characters (Black default)
Docstring Format¶
Use numpy-style docstrings:
def infer(self, file_path: Union[Path, str]) -> FileType:
"""Infer the file format from a path.
Parameters
----------
file_path : Union[Path, str]
Path to the file to analyze.
Returns
-------
FileType
Inferred extensions and MIME types.
Raises
------
FileNotFoundError
If the file does not exist.
"""
Naming Conventions¶
- Classes:
PascalCase(e.g.,MagicInferencer) - Functions/Methods:
snake_case(e.g.,infer) - Constants and registries:
UPPER_SNAKE_CASE(private registries may use a leading underscore, e.g.,_BACKEND_MAP)
Adding New Features¶
Adding a New Inferencer¶
-
Create inferencer class:
-
Register in
auto_inferencer.py(optional): -
Update type definitions:
-
Write tests:
-
Update documentation:
- Add to README.md
- Create API documentation in
docs/api/ - Add examples to
docs/user-guide.md
Adding Tests¶
Follow existing test patterns:
- Use fixtures from
conftest.py - Mock external dependencies when appropriate
- Test error cases (FileNotFoundError, ValueError, RuntimeError)
- Name tests after observable behavior
- Keep assertions deterministic and focused on the public contract
Example:
def test_infer_accepts_string_path(sample_text_file):
inferencer = MagicInferencer()
file_type = inferencer.infer(str(sample_text_file))
assert ".txt" in file_type.extensions
Commit Guidelines¶
Follow conventional commit format:
Types:
- feat: New feature
- fix: Bug fix
- docs: Documentation changes
- test: Test additions/changes
- refactor: Code refactoring
- style: Code style changes
- chore: Build/tooling changes
Example:
feat(inferencer): add CustomInferencer class
Implements a new inferencer that uses custom detection logic.
Includes tests and documentation updates.
Closes #123
Pull Request Process¶
-
Create a branch:
-
Make changes:
- Write code
- Add tests
- Update documentation
-
Ensure all tests pass
-
Commit changes:
-
Push and create PR:
-
PR Checklist:
- [ ] All tests pass
- [ ] Code follows style guidelines
- [ ] Documentation updated
- [ ] No lint errors
- [ ] Commit messages follow conventions
Documentation¶
Updating Documentation¶
- Markdown files in
docs/directory - API docs auto-generated from docstrings
- Examples in
docs/user-guide.md - README.md for GitHub overview
Adding API Documentation¶
When adding new classes/methods:
1. Add numpy-style docstrings
2. Include examples in docstrings
3. Update relevant markdown files in docs/api/
Testing Strategy¶
Unit Tests¶
- Mock external dependencies
- Test individual methods
- Fast execution
Integration Tests¶
- Use real files (via fixtures)
- Test end-to-end flows
- Verify actual detection accuracy
Test Coverage¶
Aim for high test coverage: - All public methods tested - Error cases covered - Edge cases handled
The conformance suite evaluates every verified inventory record across all four inference strategies. See Backend Conformance for the review, runtime, and baseline methodology.
Questions?¶
If you have questions: 1. Check existing documentation 2. Review existing code for patterns 3. Open an issue for discussion
Thank you for contributing! 🎉