Skip to content

Add Pydantic model CLI conversion and improve error handling#258

Open
ejseqera wants to merge 7 commits intomainfrom
refactor/pydantic-models
Open

Add Pydantic model CLI conversion and improve error handling#258
ejseqera wants to merge 7 commits intomainfrom
refactor/pydantic-models

Conversation

@ejseqera
Copy link
Member

Add Pydantic model CLI conversion and improve error handling

Summary

This PR refactors the architecture to simplify the transformation pipeline from Pydantic models to CLI commands and adds a --traceback flag to reduce verbose error output for better user experience.

Changes

1. Model-to-CLI Conversion (to_cli_args() method)

  • Added base to_cli_args() method in SeqeraResource (seqerakit/models/base.py) that converts Pydantic models directly to CLI argument lists
  • Implemented model-specific overrides for resources with positional arguments:
    • Credential: type as positional argument
    • ComputeEnv: type and config-mode as positional arguments
    • Action: type as positional, params excluded
    • Pipeline: URL as positional, params excluded
    • Launch: pipeline as positional, params excluded

2. Simplified Command Architecture

  • Added Command.execute() method (seqerakit/helper.py) for self-executing commands
  • Simplified CommandBuilder classes to use model.to_cli_args() instead of manual argument building
  • Simplified handler functions to use command.execute(sp) pattern

Before:

ModeldictArgumentBuilderargs listCommandextract argscall method

After:

Modelto_cli_args() → Commandcommand.execute(sp)

3. Error Handling Improvements

  • Added --traceback flag to control traceback visibility (seqerakit/cli.py)
  • Hides verbose tracebacks by default for cleaner error messages
  • Enables full tracebacks when debugging with --traceback
  • Improved Pydantic ValidationError formatting with field-level error messages
  • Added catch-all exception handler for unexpected errors

Migration Notes

No migration required - this is a refactoring with full backward compatibility.

ejseqera and others added 6 commits May 28, 2025 23:00
This commit includes two major improvements:

1. Add to_cli_args() method to Pydantic models
   - Implement base to_cli_args() in SeqeraResource
   - Add model-specific overrides for Credential, ComputeEnv, Action, Pipeline, and Launch
   - Simplify CommandBuilder classes to use model's to_cli_args()
   - Add Command.execute() method for self-executing commands
   - Simplify handler functions to use command.execute(sp)

2. Add --traceback flag to reduce verbose error output
   - Hide tracebacks by default for cleaner error messages
   - Add --traceback flag to show full tracebacks when debugging
   - Improve Pydantic ValidationError formatting
   - Add catch-all exception handler

Tests:
   - Add test_to_cli_args.py with 28 tests for model CLI conversion
   - Add test_command_execute.py with 15 tests for command execution
   - Add tests for --traceback flag behavior
   - All 184 tests passing

🤖 Generated with Claude Code

Co-Authored-By: Claude <[email protected]>
- Remove duplicate 'labels' key in ComputeEnv.from_api_response()
- Fix type hint in Pipeline.from_api_response() (Pipelines -> Pipeline)
- Apply ruff formatting and trailing whitespace fixes

🤖 Generated with Claude Code

Co-Authored-By: Claude <[email protected]>
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