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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__/
dist/
*.egg-info/
.DS_Store
tests/.cache/
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ Functional against Pydantic 2.13. Four codegen quirks from `datamodel-code-gener
3. **`RootModel[str]` wrappers on ID types.** Every `<ThingId>` was a wrapper class forcing `some_thing.id.root`; converted to `TypeAlias = Annotated[str, Field(pattern=…)]` so `.id` reads as a plain str while Pydantic still validates the pattern on load.
4. **Empty discriminated-union bases.** `Move`, `OracleRollable`, `OracleRollableTable`, `EmbeddedOracleRollable`, `OracleCollection` were empty base classes with `extra='allow'`; rewritten to `Annotated[Union[...], Field(discriminator=…)]` unions so real fields are attributes, not `__pydantic_extra__`.

### Known drift ⚠️
### Schema line

`models.py` here was regenerated from **schema line 0.1.0**. The content repos ship **schema 0.2.0** on `main`. Loading a live content payload today fails validation on `datasworn_version` (and probably a lot more). Fixing this = **regenerate `models.py` against the current `@datasworn-community/core` schema, then re-run the post-processor**. The end-to-end validation tests in `tests/test_load_rules_packages.py` are marked `xfail` until that happens; when the regen lands they should flip to green and the `xfail` markers should be removed.
`models.py` here was regenerated from **schema line 0.2.0** — the same line the content repos currently ship on `main`. End-to-end validation tests fetch live content on first run and pass against all official rulesets (`classic`, `delve`, `lodestar`, `starforged`, `sundered_isles`) plus community `ancient_wonders` and `fe_runners`.

`ironsmith` and `starsmith` are `xfail`ed against **known content-quality bugs** in the community-content repo (option `[key]` values containing spaces, which don't match the `DictKey` pattern `^[a-z][a-z0-9_]*$`) — not drift, and not fixable on the Python side. Bugs to file against `datasworn-community/community-content`.

Still outstanding (nice-to-have, not blocking):

Expand All @@ -68,31 +70,25 @@ Tests fetch the current content from `official-content` and `community-content`

When `@datasworn-community/core` bumps its schema line:

1. Download the current source schema:

```sh
curl -sSL https://raw.githubusercontent.com/datasworn-community/datasworn/main/packages/core/json/datasworn-source.schema.json > /tmp/datasworn-source.schema.json
```

2. Regenerate `models.py` with datamodel-code-generator (or your preferred tool):
1. Regenerate `models.py` with datamodel-code-generator directly from the current distribution schema (the shape content JSON validates against):

```sh
uvx datamodel-code-generator \
--input /tmp/datasworn-source.schema.json \
uvx --from 'datamodel-code-generator[http]' datamodel-codegen \
--url https://raw.githubusercontent.com/datasworn-community/datasworn/main/packages/core/json/datasworn.schema.json \
--input-file-type jsonschema \
--output packages/core/src/datasworn/core/models.py \
--output-model-type pydantic_v2.BaseModel \
--target-python-version 3.14 \
--use-annotated
```

3. Re-run the post-processor:
2. Re-run the post-processor to apply the five rewrites (date-pattern strip, stub → list rewrite, RootModel[str] → TypeAlias, discriminated-union base resolution, `field_X` → `X` rename):

```sh
uv run python scripts/post_process_models.py
```

4. Run tests. The `xfail` markers on `test_load_rules_packages.py` should flip green — remove the markers, commit, publish a new core version.
3. Run tests. `test_load_rules_packages.py` fetches live content on first run and validates against every ruleset — a green run confirms the regenerated models still match what the content repos ship. Bump `packages/core/pyproject.toml` and publish.

## Provenance

Expand Down
9 changes: 4 additions & 5 deletions packages/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ authors = [
]
requires-python = ">=3.14"
dependencies = [
# 2.13 works because `scripts/post_process_models.py` rewrites two codegen
# bugs that 2.13 catches: string `pattern` constraints on `date` fields, and
# empty stub models where the generator should have emitted `list[X]`.
# Bumping past 2.13 requires re-running the post-processor after any
# models.py regeneration (see the script's docstring for details).
# 2.13 works because `scripts/post_process_models.py` rewrites five codegen
# misbehaviors that pydantic (correctly) rejects or that would leave real
# attributes stuck in `__pydantic_extra__`. See the script's docstring for
# the full list; re-run it after any models.py regeneration.
"pydantic[email]>=2.13.4,<2.14",
]

Expand Down
Loading