Repository navigation
feat(cli): add --json support to pyensembl list (closes #512) - #526
Merged
Merged
Conversation
`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>
Contributor
Review & downstream perspective from
|
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.
Summary
Closes #512.
pyensembl list --jsoncurrently fails with--json requires inspect, available, or verify. This PR addslistas 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_installed_genome_rows()fromformat_installed_genomes(). The helper returns(rows, root)where every row is a plain dict with keysspecies,assembly,release,annotation,reference_dna, andcache_directory(absolute path). Absent fields useNoneso the caller can serialise without further conversion.format_installed_genomes_json()which calls_installed_genome_rowsand returnsjson.dumps(rows, indent=2). An empty cache produces[](consistent with the other--jsoncommands) rather than the prose "No genomes installed in …" message.format_installed_genomes()to delegate to the new helper; table output is unchanged.validate_argumentsto accept"list"as a valid--jsontarget; update the error message.list --jsonbranch inshell.run.--jsonhelp text to mentionlist.docs/reference/cli.md--jsonflag description to includelist.pyensembl list --jsonto the examples block.Tests
test_cli_actions.py: addedlisttotest_validate_arguments_accepts_matching_flags; removed the now-invalid("list", True, …)parametrize case.test_cli_errors.py: the error-path test now usesinstall --json(still an invalid combination) and asserts the updated message.test_data_management.py: same change — switches fromlist --jsontoinstall --jsonfor the negative test.test_list_json_emits_valid_json_arrayintest_cli_output.py: verifies key set, field values (species, assembly, release, annotation, cache_directory), and that partially-installed releases appear correctly.test_list_json_empty_cache_emits_empty_array: verifies[]output for an empty cache.Example
🤖 Generated with Claude Code