Skip to content

Make bkbit usable straight after pip install (no taxonomy pre-step) - #91

Merged
puja-trivedi merged 1 commit into
mainfrom
remove_taxonomy_download_requirement
Aug 6, 2026
Merged

Make bkbit usable straight after pip install (no taxonomy pre-step)#91
puja-trivedi merged 1 commit into
mainfrom
remove_taxonomy_download_requirement

Conversation

@puja-trivedi

Copy link
Copy Markdown
Collaborator

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.

`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>
@puja-trivedi
puja-trivedi merged commit 331d151 into main Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant