This document describes the coding principles and conventions for the fetchbib project.
fetchbib is a CLI tool that resolves DOIs and search queries into formatted BibTeX entries. The main entry point is fbib.
uv tool install -e . # Install tool as editable to reflect latest changes immediately
uv run pytest # Run tests- Use
uvoverpipfor all dependency management and script execution - Dependencies are defined in
pyproject.toml
This project follows test-driven development (TDD):
- Write tests first, then implement the feature
- Run tests frequently during development:
uv run pytest - All new functionality should have corresponding tests
Test organization:
- Unit tests mock external dependencies (no network calls)
- Integration tests are marked with
@pytest.mark.integrationand excluded by default - Run integration tests explicitly:
uv run pytest -m integration - Group tests by functionality using test classes (e.g.,
TestInputParsing,TestErrorHandling)
- Use black for code formatting
- Follow PEP 8 conventions
- src layout: Package lives under
src/fetchbib/ - Single responsibility: Each module has a focused purpose
cli.py- Argument parsing and main entry pointresolver.py- DOI resolution and Crossref API callsformatter.py- BibTeX string formattingconfig.py- User configuration persistence
- Small, focused functions: Each function does one thing well
- Use return type annotations on all functions (e.g.,
-> str,-> bool) - Use parameter type hints (e.g.,
value: str,verbose: bool)
- Every module starts with a docstring explaining its purpose
- Public functions have docstrings describing behavior and exceptions
- Use inline comments sparingly, only for non-obvious logic
- Use custom exception classes for domain-specific errors (e.g.,
ResolverError) - Validate arguments early with clear error messages
- Handle errors gracefully—one failure shouldn't stop processing of other inputs
- Minimize dependencies (currently just
requests) - Prefer standard library where possible (
argparse,json,pathlib) - Avoid unnecessary abstractions
- stdout: Only output results (BibTeX entries)
- stderr: All errors, warnings, and verbose/informational messages
- Exit codes:
0- Success1- Runtime error (resolution failure, file not found, no inputs)2- Argument error (invalid flag combinations, missing required args)
The specs/ directory contains detailed specifications for each module (not tracked in git):
| Spec File | Source File | Purpose |
|---|---|---|
specs/formatter.md |
formatter.py |
BibTeX formatting rules and options |
specs/resolver.md |
resolver.py |
DOI resolution, arXiv support, Crossref search |
specs/cli.md |
cli.py |
CLI arguments, flags, and behavior |
specs/integration.md |
test_integration.py |
Live API test cases |
specs/packaging.md |
pyproject.toml |
Build configuration and project metadata |
When modifying a module, update the corresponding spec file to keep documentation in sync with the implementation.
- Write clear, descriptive commit messages
- Do not mention Claude or AI assistance in commit messages