-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Pydantic model for the serialization schema (#888)
This PR ports the pydantic definition from guppy (including CQCL/guppylang#172), and updates it to sync up with the current schema. Changes to the schema: - Renamed the `InputExtensions` class to `ExtensionSet` - Added a named definition for `Const` - Dropped `DummyOp`. It was referenced in a couple field types, but the model was never defined. The main difference with the model in `guppy` is the use of `RootModel`-based classes instead of variables assigned to a `TypeAliasType` for defining aliases on type unions. They both work the same, but `mypy` doesn't like using variables in types. Additionally, I updated some READMEs and added a CI check to ensure that the json in `specification/schema/` is always up to date.
- Loading branch information
Showing
17 changed files
with
1,334 additions
and
311 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ jobs: | |
python: | ||
- 'quantinuum-hugr-py/**' | ||
- 'pyproject.toml' | ||
- 'specification/schema/**' | ||
check: | ||
needs: changes | ||
|
@@ -74,16 +75,54 @@ jobs: | |
- name: Run tests | ||
run: poetry run pytest | ||
|
||
# Ensure that the serialization schema is up to date | ||
serialization-schema: | ||
needs: [changes] | ||
if: ${{ needs.changes.outputs.python == 'true' }} | ||
name: Check serialization schema | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Run sccache-cache | ||
uses: mozilla-actions/[email protected] | ||
- name: Install poetry | ||
run: pipx install poetry | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
cache: "poetry" | ||
- name: Install the project libraries | ||
run: poetry install | ||
- name: Generate the updated schema | ||
run: | | ||
poetry run python scripts/generate_schema.py specification/schema/ | ||
- name: Check if the schema is up to date | ||
run: | | ||
git diff --exit-code --name-only specification/schema/ | ||
if [ $? -ne 0 ]; then | ||
echo "The serialization schema is not up to date" | ||
echo "Please run 'just update-schema' and commit the changes" | ||
exit 1 | ||
fi | ||
# This is a meta job to mark successful completion of the required checks, | ||
# even if they are skipped due to no changes in the relevant files. | ||
required-checks: | ||
name: Required checks 🐍 | ||
needs: [changes, check] | ||
if: always() | ||
needs: [changes, check, serialization-schema] | ||
if: ${{ !cancelled() }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Fail if required checks failed | ||
if: (failure() || cancelled()) | ||
# This condition should simply be `if: failure() || cancelled()`, | ||
# but there seems to be a bug in the github workflow runner. | ||
# | ||
# See https://github.com/orgs/community/discussions/80788 | ||
if: | | ||
needs.changes.result == 'failure' || needs.changes.result == 'cancelled' || | ||
needs.check.result == 'failure' || needs.check.result == 'cancelled' || | ||
needs.serialization-schema.result == 'failure' || needs.serialization-schema.result == 'cancelled' | ||
run: | | ||
echo "Required checks failed" | ||
echo "Please check the logs for more information" | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.