Skip to content

Align CLI arguments with reader APIs for full parameter consistency#321

Merged
LucaMarconato merged 11 commits intomainfrom
copilot/fix-343cb2c5-5474-4b02-b011-67557f9c973a
May 5, 2026
Merged

Align CLI arguments with reader APIs for full parameter consistency#321
LucaMarconato merged 11 commits intomainfrom
copilot/fix-343cb2c5-5474-4b02-b011-67557f9c973a

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 5, 2025

Fixes inconsistencies between the CLI interface (__main__.py) and reader APIs by ensuring all reader parameters are available through the command line interface.

Problem

The CLI exposed only a subset of reader API parameters, creating inconsistency between programmatic and command-line interfaces. Users could not access full reader functionality via CLI, limiting automation and advanced use cases.

Specific issues identified:

  • Missing non-kwargs parameters (e.g., raster_models_scale_factors in seqfish, var_names_make_unique in visium readers)
  • Complex kwargs parameters (imread_kwargs, image_models_kwargs, labels_models_kwargs) not accessible via CLI
  • Inconsistent parameter availability across different readers

Solution

1. Added Missing Parameters

Fixed real parameter mismatches where non-kwargs parameters were missing from CLI:

  • Seqfish: Added --raster-models-scale-factors parameter
  • Visium: Added --var-names-make-unique parameter
  • Visium HD: Added --var-names-make-unique parameter
  • MACSima: Added --parsing-style parameter with proper choice validation

2. JSON String Support for kwargs Parameters

Implemented JSON string parsing for complex Mapping[str, Any] parameters that cannot be directly represented as CLI arguments:

# Before: Limited to simple parameters only
spatialdata_io xenium --input /data --output /output.zarr --transcripts true

# After: Full API access via JSON kwargs
spatialdata_io xenium --input /data --output /output.zarr \
  --transcripts true \
  --imread-kwargs '{"chunks": true}' \
  --image-models-kwargs '{"scale_factors": [2, 2, 2, 2]}' \
  --labels-models-kwargs '{"rgb": null}'

All kwargs parameters now support JSON string input with:

  • Default behavior preserved: Empty JSON '{}' maintains existing CLI behavior
  • Error handling: Clear JSON parsing error messages for malformed input
  • Type safety: Proper validation and conversion to Python dictionaries

3. Comprehensive Coverage

Updated all 15 reader CLI commands to achieve 100% parameter alignment:

  • codex, cosmx, curio, dbit, iss, macsima, mcmicro, merscope, seqfish, steinbock, stereoseq, visium, visium-hd, xenium
  • Added 40+ kwargs parameters across all readers
  • Maintained exact parameter names, types, and defaults from reader APIs

Examples

# ISS with advanced configuration
spatialdata_io iss \
  --input /path/to/data \
  --output /path/to/output.zarr \
  --raw-relative-path raw.tif \
  --labels-relative-path labels.tif \
  --h5ad-relative-path counts.h5ad \
  --imread-kwargs '{"chunks": true}' \
  --image-models-kwargs '{"scale_factors": [2, 2, 2, 2]}'

# Merscope with custom backend and processing
spatialdata_io merscope \
  --input /path/to/data \
  --output /path/to/output.zarr \
  --backend rioxarray \
  --image-models-kwargs '{"chunks": [1, 512, 512]}'

Backward Compatibility

All existing CLI usage patterns continue to work unchanged. The new parameters are optional with sensible defaults that preserve current behavior.

Testing

  • Syntax validation passed for all modifications
  • JSON parsing functionality verified with comprehensive test cases
  • Import validation confirms no breaking changes to module structure

The CLI now provides complete functional parity with all reader APIs while maintaining usability for common use cases.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 5, 2025 14:54
…m_hd, and macsima

Co-authored-by: LucaMarconato <2664412+LucaMarconato@users.noreply.github.com>
Co-authored-by: LucaMarconato <2664412+LucaMarconato@users.noreply.github.com>
Copilot AI changed the title [WIP] Align CLI Arguments in __main__.py with API Specifications in Readers Align CLI arguments with reader APIs for full parameter consistency Sep 5, 2025
Copilot AI requested a review from LucaMarconato September 5, 2025 15:01
LucaMarconato and others added 3 commits May 4, 2026 19:38
- Move import json to top-level and introduce _parse_json_param helper to
  eliminate repeated try/except blocks in every wrapper function
- Add missing --imread-kwargs option to macsima_wrapper (the reader exposes it
  but the CLI did not)
- Fix trailing whitespace in multi-line function signatures from the PR

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 5, 2026

Codecov Report

❌ Patch coverage is 89.58333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.77%. Comparing base (55c8539) to head (ce9e3b0).

Files with missing lines Patch % Lines
src/spatialdata_io/__main__.py 89.58% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #321      +/-   ##
==========================================
+ Coverage   61.85%   62.77%   +0.91%     
==========================================
  Files          26       26              
  Lines        3138     3175      +37     
==========================================
+ Hits         1941     1993      +52     
+ Misses       1197     1182      -15     
Files with missing lines Coverage Δ
src/spatialdata_io/__main__.py 84.54% <89.58%> (+3.12%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

LucaMarconato and others added 4 commits May 5, 2026 10:20
CLI fixes (all matching current reader APIs):
- xenium: remove deprecated --n-jobs, fix cells_as_circles default False,
  add --gex-only (default True)
- visium_hd: add missing type=bool to --load-segmentations-only,
  add --gex-only (default False)
- seqfish: change --rois from IntRange to str (reader uses list[str]),
  change --raster-models-scale-factors from float to int

Tests (test_xenium.py, no real data required):
- test_cli_xenium_invalid_json_rejected: all three kwargs options reject
  malformed JSON with a clear error message
- test_cli_xenium_valid_json_forwarded: valid JSON is parsed and forwarded
  to the reader as a dict (verified via mock)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
tests/test_cli_alignment.py checks that every non-path parameter of each
reader function is exposed by its CLI wrapper. The test runs in CI on every PR
so future reader additions automatically turn the suite red until __main__.py
catches up.

Design notes:
- Uses inspect.signature on wrapper.callback (Click replaces the function with
  a Command object; the Python signature lives in .callback)
- _READER_EXCEPTIONS allows intentionally hidden params (currently: xenium
  n_jobs, which is deprecated and has no effect)
- No real data required; pure import + introspection

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Check both directions (symmetric difference): reader params absent from
  CLI *and* CLI params absent from reader (stale options)
- Expand docstring to explain what the test does NOT cover (types, defaults)
  and include a ready-to-run claude command for manual type/default audits

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@LucaMarconato LucaMarconato marked this pull request as ready for review May 5, 2026 09:53
@LucaMarconato
Copy link
Copy Markdown
Member

LucaMarconato commented May 5, 2026

The CLI is now brought back in sync with the readers. In particular this PR adds all those remaining missing arguments to the CLI that required a JSON representation (dict arguments) and also adds a test to help spotting divergences between the readers and the CLI.

@LucaMarconato LucaMarconato merged commit fafeac8 into main May 5, 2026
5 checks passed
@LucaMarconato LucaMarconato deleted the copilot/fix-343cb2c5-5474-4b02-b011-67557f9c973a branch May 5, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants