Load CLI subcommands from entry points#449
Open
Seth Fitzsimmons (mojodna) wants to merge 9 commits intodevfrom
Open
Load CLI subcommands from entry points#449Seth Fitzsimmons (mojodna) wants to merge 9 commits intodevfrom
Seth Fitzsimmons (mojodna) wants to merge 9 commits intodevfrom
Conversation
Every other package had its tests/ directory in pythonpath; cli was the only one missing, making its conftest imports rely on rootdir discovery.
Extracts filter_models() and resolve_types() into core/discovery.py. Union-building helpers (create_union_type_from_models, _discriminated_union, _can_discriminate, _type_literal) go to a new core/union.py module. ModelDict and UnionType type aliases live alongside the functions that produce them (discovery.py and union.py respectively). Both CLI and the upcoming validation package import these from core, avoiding a cross-dependency.
The cli() group discovers and loads subcommands from the "overture.schema.cli" entry point group at import time. Built-in commands (json-schema, list-types, validate) are registered first via decorators; plugins that collide with built-in names are skipped. Broken plugins emit a warning to stderr and don't prevent the CLI from starting.
Empty package with entry point registration for the "validate" subcommand in the "overture.schema.cli" group. Code will be moved from overture-schema-cli in subsequent commits.
Moves validate command, type_analysis, error_formatting, data_display to the new package. types.py retains only ValidationErrorDict and ErrorLocation (ModelDict and UnionType are in core). output.py (rewrap) is deliberately duplicated -- both packages keep a copy. A future CLI helper package will consolidate shared utilities. The validate command is now loaded by the CLI via entry point. CLI package is stripped down to built-in commands (list-types, json-schema).
Validation test files (type_analysis, error_formatting, data_display, heterogeneous_collections) move to the validation package. Validate command and function tests extracted from CLI test modules. CLI retains list-types, json-schema, and plugin loading tests.
Drop pyyaml and yamlcore (validation-only). Declare overture-schema-system explicitly (used by json-schema command).
Verify validate appears in --help and works end-to-end when the validation package is installed.
Remove dead code, extract duplicated patterns, and tighten types across cli, core, and validation packages. Deduplication: - Merge _format_nested_path / format_path into one formatter - Extract _filter_union_markers for repeated structural analysis pattern in error_formatting - Extract get_effective_message for repeated ctx["error"] preference pattern - Replace 5 manual dict-building sites with defaultdict API cleanup: - Remove use_overture_types bool from filter_models / resolve_types; callers pass namespace="overture" directly - Remove unused get_registered_model - Remove dead show_feature_data parameter and its branch Type correctness: - handle_generic_error -> NoReturn (was -> None) - Union type truthiness checks -> explicit is not None - cast(str, _type_literal(f)) -> assertion - hasattr(metadata, "discriminator") -> getattr check (FieldInfo always has the attr, defaulting to None) - Nested union detection narrowed from get_origin is not None to explicit Union type check - Hardcoded context_size replaced with DEFAULT_CONTEXT_SIZE filter_models ValueError now includes the filter parameters in the message for easier diagnosis of typos.
| description = "Validation command for Overture Maps schema CLI" | ||
| dynamic = ["version"] | ||
| license = "MIT" | ||
| name = "overture-schema-validation" |
Collaborator
There was a problem hiding this comment.
Can we have a slight restructuring of the package names?
Current:
- overture-schema-addresses-theme
- overture-schema-addresses-theme
- overture-schema-base-theme
- overture-schema-cli
- overture-schema-validation
- ...
Proposed:
- overture-schema-theme-addresses
- overture-schema-theme-base
- overture-schema-cli
- overture-schema-cli-validation
- ...
This will keep the related packages visually grouped
Collaborator
Author
There was a problem hiding this comment.
I intentionally named this -validation; code generation has a minor validation requirement (we want to ensure that the TOML examples are valid) and I can imagine pulling in the Parquet file validation from #437. I also intend this to be a library for validation, not just the CLI.
For the theme packages, let's stick that on the WG agenda for broader discussion.
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
Refactor the CLI so installed packages contribute subcommands via setuptools entry points, then extract
validateinto a standaloneoverture-schema-validationpackage to prove the mechanism.cli()group discovers subcommands from theoverture.schema.clientry point group at import timeoverture-schema-validationregisters thevalidatesubcommand through an entry point -- no CLI code changes neededoverture-schema-coreto avoid cross-dependenciesMotivation
The CLI package was accumulating domain-specific command implementations as direct dependencies. Entry-point-based plugin loading inverts this: command packages depend on core or system, and the CLI discovers them at runtime. Adding a new subcommand (e.g.
generate) means adding a package with an entry point -- no changes to the CLI.Entry point registration
Packages register subcommands by declaring an entry point in
pyproject.toml:The value points to a Click command object. Built-in commands (
json-schema,list-types) take precedence on name collision; broken plugins warn to stderr without crashing.Squash commit message
Test plan
make checkpasses (pytest + ruff + mypy across workspace)overture-schema --helplistsvalidatewhen validation package is installedoverture-schema validateworks end-to-endjson-schema,list-types) work independently of validation package