How magikcarp/snakecite works
Project type and purpose
• snakecite is a lightweight, command-line Python tool that automates retrieval and generation of citation information (BibTeX/JSON) for the packages used in a Snakemake workflow or plain requirements files.
• It is not a web service or microservice suite, but a single‐process CLI application that orchestrates a pipeline of sub‐components: input parsing, metadata retrieval (PyPI, Bioconda, Anaconda, GitHub), formatting, and output.
File structure
• Top-level files:
• pyproject.toml – build configuration & entry point
• README.md – documentation
• tests/ – unit tests
• src/snakecite/
• __main__.py – CLI entrypoint and argument parsing
• cite.py – core logic: parsing inputs, querying APIs, formatting citations
• tests/test_cite.py – verifies citation retrieval and formatting
README for additional insights
• Supports three input modes: DOI URL, requirements.txt, environment.yaml (or directories of Snakemake YAML files).
• Queries external registries: PyPI, Bioconda, Anaconda; falls back to GitHub API for author metadata.
• Produces BibTeX or JSON; writes to STDOUT or file.
• All-batteries-included: uses only Python standard library.
Main components and their interactions
a. Components
1. CLI Interface (in __main__.py)
2. Input Parser (requirements.txt, environment.yaml, Snakemake workflows)
3. Citation Retriever
– PyPI API Client
– Bioconda/Anaconda Registry Client
– GitHub API Client (with optional token)
4. Citation Generator (formats metadata into BibTeX/JSON)
5. Output Writer (stdout or file)
6. Logging / Error Handler
7. Tests (isolated against cite.py functions)
b. Relationships & data flow
• User invokes “snakecite” → CLI Interface
• CLI parses arguments → hands off to Input Parser → emits list of package identifiers
• For each package:
– Citation Retriever queries external services in sequence (PyPI → Bioconda → Anaconda → GitHub fallback)
– Returns normalized metadata (authors, title, DOI, URL)
• Citation Generator formats metadata → structured BibTeX or JSON object
• Output Writer streams formatted citations to STDOUT or writes to designated file
• Logging component captures errors/warnings (e.g., rate limiting), surfaces to user
c. Architectural patterns & design principles
– Pipeline / chain of responsibility: each stage has single responsibility
– Dependency inversion: core logic in cite.py is decoupled from data sources via client abstractions
– Pure-function style in retrieval and formatting modules → high test coverage
d. Key technologies and libraries
– Python standard library (argparse, json, urllib.request, xml)
– pytest for testing
– GitHub REST API (via urllib)
– PyPI JSON endpoints
– YAML parsing (via standard library’s minimal safe parser if needed)