Repository navigation
draft: native types codegen design and generated schemas - #857
stobrien89 wants to merge 5 commits into
Conversation
ab0648a to
5d75777
Compare
5d75777 to
cf12e65
Compare
jonathan343
left a comment
There was a problem hiding this comment.
Thanks @stobrien89!
The design itself looks great. Most of my feedback is about keeping the doc focused on the goal state. Anything that describes current state, specific PRs, or the Java migration will go stale as we land the implementation, so I'd move that to the PR description or #797.
69872c9 to
bbf1e2a
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Output-path safety, stale-file cleanup, selector evaluation, and generated-name collisions remain unresolved.
5 open issues
Reject drive-qualified path components before native path construction · New Prevent stale cleanup through symlinked ancestor paths · New Detect public name collisions across declarations and synthesized classes · New Include resource lifecycle and collection operations in topdown filter · New Reject non-finite decimal trait values before ordered comparisons · New
What changed in this PR
This PR lays the foundation for native Python standalone-types generation under #797. It adds compact schema emission and shared generation infrastructure while leaving the Java generator authoritative.
Changes:
- Add selector parsing, standalone-type selection, generation plans, and compact schema emission.
- Introduce dependency tracking and staged file publication with ownership manifests.
- Expand unit coverage and document the planned standalone-types pipeline.
| File | Description |
|---|---|
packages/smithy-python/tests/unit/test_writer.py |
Test dependency collection from type references. |
packages/smithy-python/tests/unit/test_symbols.py |
Cover dependency metadata and streaming schema names. |
packages/smithy-python/tests/unit/test_selectors.py |
Test selector parsing and evaluation. |
packages/smithy-python/tests/unit/test_schemas.py |
Test compact encoding, hydration, and deterministic output. |
packages/smithy-python/tests/unit/test_generation.py |
Test generation settings, context, and plans. |
packages/smithy-python/tests/unit/test_files.py |
Test staging, ownership, cleanup, and path checks. |
packages/smithy-python/tests/unit/test_dependencies.py |
Test dependency validation and merging. |
packages/smithy-python/tests/unit/test_data_selection.py |
Cover standalone-type selection rules. |
packages/smithy-python/src/smithy_python/writer.py |
Record dependencies from nested references. |
packages/smithy-python/src/smithy_python/symbols.py |
Plan schema and union names; attach dependencies. |
packages/smithy-python/src/smithy_python/selection.py |
Add standalone-type selection and dependency closure. |
packages/smithy-python/src/smithy_python/schemas.py |
Plan and emit compact, lazy schemas. |
packages/smithy-python/src/smithy_python/model/_shapes.py |
Define shared declaration shape types. |
packages/smithy-python/src/smithy_python/model/__init__.py |
Export declaration shape types. |
packages/smithy-python/src/smithy_python/generation.py |
Introduce shared settings, context, and plans. |
packages/smithy-python/src/smithy_python/files.py |
Implement staged publication and ownership tracking. |
packages/smithy-python/src/smithy_python/exceptions.py |
Add selector syntax errors. |
packages/smithy-python/src/smithy_python/dependencies.py |
Define dependency records and runtime requirements. |
packages/smithy-python/src/smithy_python/_selector.py |
Implement Smithy selector parsing and evaluation. |
packages/smithy-python/.changes/next-release/smithy-python-feature-schema-generation.json |
Announce native compact schema generation. |
packages/smithy-core/src/smithy_core/_schema_compact.py |
Expose the compact encoding version. |
designs/codegen/writer.md |
Document writer dependency tracking. |
designs/codegen/types.md |
Describe the standalone-types architecture and compatibility goals. |
designs/codegen/symbols.md |
Document dependency-bearing type references. |
designs/codegen/selection.md |
Describe standalone selection and selectors. |
designs/codegen/index.md |
Link the standalone-types design. |
designs/codegen/cli.md |
Update documented artifact-specific selection rules. |
Review effort: Balanced
743a2bb to
eee35b8
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved correctness issues affect schema semantics, shape selection, and safe output publication.
6 open issues
Track qualification in traversal visited state · New Handle symlink aliases during output collision and cleanup checks · New Preserve primitive target identity and inherited defaults · New Include virtual trait shapes in selector starting set · New Allow empty paths in scoped context references · New Exclude streaming unions from declaration name checks · New
5 resolved since last review
Detect public name collisions across declarations and synthesized classes Prevent stale cleanup through symlinked ancestor paths Reject drive-qualified path components before native path construction Reject non-finite decimal trait values before ordered comparisons Include resource lifecycle and collection operations in topdown filter
Review effort: Balanced
| visited: set[Shape] = set() | ||
| pending = [(shape, False)] | ||
| while pending: | ||
| current, qualified = pending.pop() | ||
| if current in visited: | ||
| continue | ||
| visited.add(current) |
| parts = PurePosixPath(path).parts | ||
| current = output | ||
| for index, part in enumerate(parts): | ||
| current /= part |
| _shape_id("smithy.api#PrimitiveBoolean"): 2, | ||
| _shape_id("smithy.api#PrimitiveByte"): 5, | ||
| _shape_id("smithy.api#PrimitiveShort"): 6, | ||
| _shape_id("smithy.api#PrimitiveInteger"): 7, |
| self.shapes = tuple(shapes) | ||
| virtual_traits = _virtual_trait_shapes(model, self.shapes) | ||
| graph_shapes = (*self.shapes, *virtual_traits.values()) |
| self._ws() | ||
| if self._take("@"): | ||
| self._expect("{") | ||
| path = self._parse_path(allow_empty=False) |
|
|
||
| shapes = tuple(shape for shape in model.iter_shapes() if shape.id in closure) | ||
| _check_names( | ||
| tuple(shape for shape in shapes if shape.type in DECLARATION_TYPES), |


Issue #, if available:
#797
Description
Adds native Python schema generation and the supporting infrastructure for standalone types packages.
This PR includes the approved standalone types design and implements the schema-generation portion. Model generation and CLI integration will follow in separate PRs.
Changes
smithy-core.Follow-up work
smithy-python generate typesartifact pipeline with the CLI.Compatibility
The Java generator remains authoritative until the native implementation passes complete parity validation. Existing generation and generated packages are unaffected.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.