Skip to content

Commit

Permalink
WIP: added create_pydantic_dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
niamhdougan committed Jul 6, 2023
1 parent 59efc3f commit 58180f6
Show file tree
Hide file tree
Showing 8 changed files with 551 additions and 156 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ repos:
language: system
entry: flake8
types: [python]
# Automatically sort imports
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ibek.support",
"type": "python",
"request": "launch",
"module": "ibek.support",
"justMyCode": false
},
{
"name": "Debug Unit Test",
"type": "python",
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ install_requires =
ruamel.yaml
jsonschema
jinja2
pydantic

# Specify any package dependencies below.
# install_requires =
Expand Down Expand Up @@ -98,7 +99,7 @@ exclude =
# Run pytest with all our checkers, and don't spam us with massive tracebacks on error
addopts =
--tb=native -vv --doctest-modules --doctest-glob="*.rst"
--cov=ibek --cov-report term --cov-report xml:cov.xml
# --cov=ibek --cov-report term --cov-report xml:cov.xml
# https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings
filterwarnings = error
# Doctest python code in docs, python code in src docstrings, test functions in tests
Expand Down
7 changes: 3 additions & 4 deletions src/ibek/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import jsonschema
import typer
from apischema.json_schema import JsonSchemaVersion, deserialization_schema
from ruamel.yaml import YAML

from ibek import __version__
Expand All @@ -18,7 +17,7 @@


def make_schema(cls: type) -> Mapping[str, Any]:
return deserialization_schema(cls, version=JsonSchemaVersion.DRAFT_7)
return cls.__pydantic_model__.schema()


def version_callback(value: bool):
Expand All @@ -45,7 +44,7 @@ def ibek_schema(
output: Path = typer.Argument(..., help="The filename to write the schema to")
):
"""Produce the JSON global schema for all <support_module>.ibek.defs.yaml files"""
schema = json.dumps(make_schema(Support), indent=2)
schema = Support.__pydantic_model__.schema_json(indent=2)
output.write_text(schema)


Expand All @@ -72,7 +71,7 @@ def ioc_schema(
support = Support.deserialize(support_dict)
make_entity_classes(support)

schema = json.dumps(make_schema(IOC), indent=2)
schema = IOC.__pydantic_model__.schema_json(indent=2)
output.write_text(schema)


Expand Down
7 changes: 0 additions & 7 deletions src/ibek/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,5 @@
"""
from typing import TypeVar

from apischema import schema

#: A generic Type for use in type hints
T = TypeVar("T")


def desc(description: str):
"""a description Annotation to add to our Entity derived Types"""
return schema(description=description)
Loading

0 comments on commit 58180f6

Please sign in to comment.