Skip to content

feat(cli): add --json support to pyensembl list (closes #512) - #526

Merged
iskandr merged 3 commits into
openvax:mainfrom
thanvish21:fix/list-json-512
Nov 22, 2026
Merged

iskandr merged 3 commits into
openvax:mainfrom
thanvish21:fix/list-json-512

Conversation

@thanvish21

Copy link
Copy Markdown
Contributor

Summary

Closes #512.

pyensembl list --json currently fails with --json requires inspect, available, or verify. This PR adds list as a supported action for --json, so scripts and CI can query the installed-genome inventory without scraping the aligned text table.

Changes

pyensembl/shell.py

  • Extract _installed_genome_rows() from format_installed_genomes(). The helper returns (rows, root) where every row is a plain dict with keys species, assembly, release, annotation, reference_dna, and cache_directory (absolute path). Absent fields use None so the caller can serialise without further conversion.
  • Add format_installed_genomes_json() which calls _installed_genome_rows and returns json.dumps(rows, indent=2). An empty cache produces [] (consistent with the other --json commands) rather than the prose "No genomes installed in …" message.
  • Update format_installed_genomes() to delegate to the new helper; table output is unchanged.
  • Extend validate_arguments to accept "list" as a valid --json target; update the error message.
  • Wire up the list --json branch in shell.run.
  • Update the --json help text to mention list.

docs/reference/cli.md

  • Updated the --json flag description to include list.
  • Added pyensembl list --json to the examples block.

Tests

  • Updated test_cli_actions.py: added list to test_validate_arguments_accepts_matching_flags; removed the now-invalid ("list", True, …) parametrize case.
  • Updated test_cli_errors.py: the error-path test now uses install --json (still an invalid combination) and asserts the updated message.
  • Updated test_data_management.py: same change — switches from list --json to install --json for the negative test.
  • Added test_list_json_emits_valid_json_array in test_cli_output.py: verifies key set, field values (species, assembly, release, annotation, cache_directory), and that partially-installed releases appear correctly.
  • Added test_list_json_empty_cache_emits_empty_array: verifies [] output for an empty cache.

Example

$ pyensembl list --json
[
  {
    "species": "human",
    "assembly": "GRCh38",
    "release": "112",
    "annotation": "indexed",
    "reference_dna": null,
    "cache_directory": "/home/user/.pyensembl/GRCh38/ensembl112"
  }
]

🤖 Generated with Claude Code

`pyensembl list --json` now prints the installed-genome inventory as a
JSON array instead of raising `--json requires inspect, available, or
verify`.  Closes openvax#512.

Changes:
- Extract `_installed_genome_rows()` from `format_installed_genomes()`.
  The helper returns `(rows, root)` where every row is a plain dict with
  keys `species`, `assembly`, `release`, `annotation`, `reference_dna`
  and `cache_directory` (absolute path).  Absent fields use `None` so
  the caller can serialise without further conversion.
- Add `format_installed_genomes_json()` which calls `_installed_genome_rows`
  and returns `json.dumps(rows, indent=2)`.  An empty cache produces `[]`
  (consistent with the other `--json` commands) rather than the prose
  "No genomes installed in …" message.
- Update `format_installed_genomes()` to delegate to the new helper;
  the table output is unchanged.
- Extend `validate_arguments` to accept `"list"` as a valid `--json`
  target and update the error message to include `list`.
- Wire up the `--json` / `list` branch in `shell.run`.
- Update the `--json` help text and `docs/reference/cli.md` to document
  the new flag combination; add `pyensembl list --json` to the examples.
- Update existing tests that asserted `list --json` was an argument
  error (now valid): `test_cli_actions.py`, `test_cli_errors.py`,
  `test_data_management.py`.
- Add two new tests in `test_cli_output.py`:
  `test_list_json_emits_valid_json_array` verifies the shape, keys and
  values of the array for a populated cache;
  `test_list_json_empty_cache_emits_empty_array` verifies the `[]` output
  for an empty cache.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@iskandr

iskandr commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Review & downstream perspective from tsarina (v1.41.1)

Clean refactor extracting _installed_genome_rows() and emitting [] for an empty cache—this aligns pyensembl list --json with the machine-readable --json inventory surface across hitlist, orfdata, and tsarina, and will make it straightforward for tsarina pipelines/CI to verify installed Ensembl 112 / 115 human and mouse releases without parsing aligned tables.

Two minor suggestions

  1. Sort custom genomes together with Ensembl releases: In _installed_genome_rows(), rows.sort(...) currently runs before the custom-genome directory loop appends custom rows (inherited from the prior code). Moving the single rows.sort(...) to right before return rows, root ensures deterministic ordering in --json output when custom genomes (e.g., orfdata --annotation outputs) are present.
  2. Version bump: Note pyensembl/version.py isn't bumped in this PR—worth adding a minor/patch bump (and changelog entry) before merge/release.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 93.667% (+0.01%) from 93.656% — thanvish21:fix/list-json-512 into openvax:main

@iskandr
iskandr merged commit ef62017 into openvax:main Nov 22, 2026
9 checks passed
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.

pyensembl list has no --json, though inspect, available and verify do

3 participants