Make bkbit usable straight after pip install (no taxonomy pre-step) - #91
Merged
Merged
Conversation
`bkbit` was unusable after `pip install`: genome_annotation_translator loaded the NCBI taxonomy in the Gff3 class body, so a missing cache raised at import time and broke every subcommand, including `--help`. The cache was also 225MB of pretty-printed JSON written into site-packages, which is too large for PyPI and may be read-only or wiped on upgrade. Taxonomy access now goes through bkbit.utils.ncbi_taxonomy_cache, which serves lookups from two layers and does no work at import time: 1. A subset bundled in the wheel (ncbi_taxonomy_data/taxonomy_subset.json.gz, 575KB, the 30,618 taxa that have a GenBank common name). Covers every BICAN organism, loads offline in milliseconds. 2. The full NCBI taxonomy, downloaded only on a subset miss and cached in a per-user cache dir (BKBIT_DATA_DIR to override, BKBIT_NO_DOWNLOAD to forbid the implicit download). Written compactly; legacy in-package caches are still read but never written to. `download-ncbi-taxonomy` becomes an optional prefetch for air-gapped, CI, and container builds, and gained --data-dir. ncbi_taxonomy_data/build_subset.py regenerates the bundled subset for a newer taxonomy dump. Also fixes two further import-time crashes on the same path: `import pkg_resources` fails on Python 3.12 with modern setuptools, and it was reached from cli.py via HMBA_annotation_translator (unused import, removed) and add_dunderMethods_genomeAnnotation (switched to pathlib). pyproject.toml gains the runtime deps that were imported but undeclared (requests, tqdm, rdflib) plus platformdirs, declares package-data for the bundled subset, and requires Python >=3.9 for importlib.resources.files. Verified by installing the built wheel (803KB) into a clean venv with an empty HOME: `bkbit --help` and `bkbit gff2jsonld` on a real Ensembl GFF3 both succeed with BKBIT_NO_DOWNLOAD=1 and no cache present. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bkbitwas unusable afterpip install: genome_annotation_translator loaded the NCBI taxonomy in the Gff3 class body, so a missing cache raised at import time and broke every subcommand, including--help. The cache was also 225MB of pretty-printed JSON written into site-packages, which is too large for PyPI and may be read-only or wiped on upgrade.Taxonomy access now goes through bkbit.utils.ncbi_taxonomy_cache, which serves lookups from two layers and does no work at import time:
download-ncbi-taxonomybecomes an optional prefetch for air-gapped, CI, and container builds, and gained --data-dir. ncbi_taxonomy_data/build_subset.py regenerates the bundled subset for a newer taxonomy dump.Also fixes two further import-time crashes on the same path:
import pkg_resourcesfails on Python 3.12 with modern setuptools, and it was reached from cli.py via HMBA_annotation_translator (unused import, removed) and add_dunderMethods_genomeAnnotation (switched to pathlib).pyproject.toml gains the runtime deps that were imported but undeclared (requests, tqdm, rdflib) plus platformdirs, declares package-data for the bundled subset, and requires Python >=3.9 for importlib.resources.files.
Verified by installing the built wheel (803KB) into a clean venv with an empty HOME:
bkbit --helpandbkbit gff2jsonldon a real Ensembl GFF3 both succeed with BKBIT_NO_DOWNLOAD=1 and no cache present.