Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ For now, you can install the SDK using the following commands:
mkdir sdk

# Clone the repository
git clone https://github.com/Universal-Commerce-Protocol/python-sdk.git sdk/python

# Navigate to the directory
cd sdk/python
git clone https://github.com/Universal-Commerce-Protocol/python-sdk.git

# Install dependencies
uv sync
Expand All @@ -58,6 +55,12 @@ This project uses `uv` for dependency management.
The models are automatically generated from the JSON schemas in the UCP
Specification.

Clone the UCP main repository in the same folder:

```bash
git clone https://github.com/Universal-Commerce-Protocol/ucp.git
```

To regenerate the models:

```bash
Expand Down
41 changes: 36 additions & 5 deletions generate_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ cd "$(dirname "$0")"
OUTPUT_DIR="src/ucp_sdk/models"

# Schema directory (relative to this script)
SCHEMA_DIR="../../spec/"
SCHEMA_DIR="ucp/source"
TEMP_SCHEMA_DIR="temp_schemas"

echo "Generating Pydantic models from $SCHEMA_DIR..."
echo "Preprocessing schemas..."
python3 preprocess_schemas.py

echo "Generating Pydantic models from preprocessed schemas..."

# Check if uv is installed
if ! command -v uv &> /dev/null; then
Expand All @@ -23,14 +27,35 @@ fi
rm -r -f "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"

# Create ruff configuration for generated code
cat > "$OUTPUT_DIR/ruff.toml" << 'EOF'
# Ruff configuration for generated models
# These are auto-generated files, so we're more lenient with style rules

line-length = 120
target-version = "py311"

[lint]
select = ["E", "F", "I"]
ignore = ["E501"]

[lint.pydocstyle]
convention = "google"

[lint.per-file-ignores]
"__init__.py" = ["D104"]
"*.py" = ["D100", "D101", "D102", "D103", "D200", "D205", "D212"]
EOF

# 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
uv run \
--link-mode=copy \
--extra-index-url https://pypi.org/simple python \
-m datamodel_code_generator \
--input "$SCHEMA_DIR" \
--input "$TEMP_SCHEMA_DIR" \
--input-file-type jsonschema \
--output "$OUTPUT_DIR" \
--output-model-type pydantic_v2.BaseModel \
Expand All @@ -41,7 +66,13 @@ uv run \
--disable-timestamp \
--use-double-quotes \
--no-use-annotated \
--allow-extra-fields \
--formatters ruff-format ruff-check
--allow-extra-fields

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"

# Clean up temporary schemas
rm -rf "$TEMP_SCHEMA_DIR"

echo "Done. Models generated in $OUTPUT_DIR"
Loading
Loading