Conversation
| The models are automatically generated from the JSON schemas in the UCP | ||
| Specification. | ||
|
|
||
| Clone the UCP main repository in the same folder: |
There was a problem hiding this comment.
Consider adding as a submodule instead.
| [project] | ||
| name = "ucp-sdk" | ||
| version = "0.1.0" | ||
| version = "0.2.0" |
There was a problem hiding this comment.
Should this get in sync with the spec version? 2026.01.23 ?
| # pylint: disable=all | ||
| # pyformat: disable | ||
| """ | ||
|
|
There was a problem hiding this comment.
Why move this to a temporarily generated file? These settings take effect across subdirectories too.
There was a problem hiding this comment.
Is this tool specific to the Python repo, or is is needed for Javascript as well? Should it live in the main ucp repo instead?
| # Run generation using uv | ||
| # We use --use-schema-description to use descriptions from JSON schema as docstrings | ||
| # We use --field-constraints to include validation constraints (regex, min/max, etc.) | ||
| # Note: Formatters removed as they can hang on large schemas |
There was a problem hiding this comment.
Might be better to comment that formatting is done as a post-processing step. We still want to reformat the code to minimize accidental whitespace changes.
|
|
||
| echo "Generating Pydantic models from $SCHEMA_DIR..." | ||
| echo "Preprocessing schemas..." | ||
| python3 preprocess_schemas.py |
|
|
||
| echo "Formatting generated models..." | ||
| uv run ruff format "$OUTPUT_DIR" | ||
| uv run ruff check --fix --config "$OUTPUT_DIR/ruff.toml" "$OUTPUT_DIR" 2>&1 | grep -E "^(All checks passed|Fixed|Found)" || echo "Formatting complete" |
There was a problem hiding this comment.
If we remove --config "$OUTPUT_DIR/ruff.toml" , won't it use the settings from pyproject.toml at the top?
|
|
||
| if __name__ == "__main__": | ||
| script_dir = Path(__file__).parent | ||
| input_schemas = script_dir / "ucp" / "source" |
There was a problem hiding this comment.
Consider taking command line arguments instead.
| --allow-extra-fields | ||
|
|
||
| echo "Formatting generated models..." | ||
| uv run ruff format "$OUTPUT_DIR" |
There was a problem hiding this comment.
$OUTPUT_DIR can be omitted; the whole project will be reformatted.
This pull request introduces major improvements to the model generation workflow, schema preprocessing, and project structure for the UCP Python SDK. The most significant changes include the addition of a schema preprocessing script to resolve compatibility issues, updates to the model generation script to use preprocessed schemas, a refactor of capability and discovery profile models for clarity and separation, and enhanced formatting and linting for generated code.
Schema Preprocessing and Model Generation:
preprocess_schemas.pyscript to preprocess JSON schemas, resolving internal references and removing problematic definitions to ensure compatibility withdatamodel-code-generator. Thegenerate_models.shscript is updated to invoke this preprocessing step and to format/lint generated models using Ruff. [1] [2] [3] [4]Model and Schema Refactoring:
Formatting and Linting Improvements:
pyproject.tomland now generate a dedicatedruff.tomlin the models directory for more lenient linting of auto-generated code. The model generation script now applies formatting and lint fixes automatically. [1] [2] [3] [4]Documentation and Setup Updates:
README.mdto clarify repository cloning instructions and document the need to clone the main UCP repository for schema regeneration. [1] [2]Cleanup and Deprecation:
_internal.pymodels file, as its functionality has been replaced by the new schema-based model structure.