Skip to content

Extend CLI extension loader to support multiple target types#56

Open
tomdurrant wants to merge 1 commit into
mainfrom
cli-extension-loader
Open

Extend CLI extension loader to support multiple target types#56
tomdurrant wants to merge 1 commit into
mainfrom
cli-extension-loader

Conversation

@tomdurrant
Copy link
Copy Markdown
Contributor

Summary

Refactors the oceanum CLI entry point to support three plugin extension styles — legacy module side-effects, direct click.Command/click.Group exports, and registrar callables — while remaining fully backward-compatible with existing built-in extensions.

Changes

  • src/oceanum/__main__.py: Extracted load_cli_extensions(parent_group) function with type-dispatch on entry point return values:

    • types.ModuleType → legacy import side-effects (unchanged behaviour)
    • click.Command / click.Group → registered directly onto the parent group
    • Any other callable → called as a registrar: ep_obj(parent_group)
    • Exceptions caught per-plugin; broken plugins log to stderr without aborting startup
    • OCEANUM_CLI_DEBUG=1 enables verbose load tracing
  • tests/test_cli_extension_loader.py: New unit tests covering all four dispatch paths, broken-plugin resilience, and debug-mode safety (5 tests, no network required)

  • tests/conftest.py + tests/test_cli_storage.py: Token-gated test bootstrap normalised — requires_datamesh_token marker skips storage tests when OCEANUM_TEST_DATAMESH_TOKEN is absent

  • pyproject.toml: requires_datamesh_token pytest marker registered

  • README.md: Plugin Authoring section added with examples of all three target styles

Testing

All local/unit tests pass without a live token:

38 passed, 12 skipped (token-gated), 0 failures

Add support for three extension styles in the oceanum CLI host:
- Legacy module side effects (existing behaviour, unchanged)
- Direct click.Command/Group export
- Registrar callable (receives parent group, registers commands)

Broken plugins are caught and logged to stderr without aborting
startup. An OCEANUM_CLI_DEBUG env var enables verbose load tracing.

Also normalise the token-gated test bootstrap: conftest.py uses
pytest hooks to skip requires_datamesh_token tests when the env var
is absent, and test_cli_storage.py is marked accordingly.

Add unit tests covering all four dispatch paths plus broken-plugin
resilience and debug-mode safety.
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