Skip to content
Draft
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
9 changes: 6 additions & 3 deletions harp/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from os import PathLike
from typing import TextIO, Union

from pydantic_yaml import parse_yaml_raw_as
import yaml
from pydantic import TypeAdapter

from harp.model import Model, Registers

Expand All @@ -13,7 +14,8 @@ def _read_common_registers() -> Registers:

file = resources.files(__package__) / "common.yml"
with file.open("r") as fileIO:
return parse_yaml_raw_as(Registers, fileIO.read())
raw_reg = yaml.safe_load(fileIO.read())
return TypeAdapter(Registers).validate_python(raw_reg)


def read_schema(file: Union[str, PathLike, TextIO], include_common_registers: bool = True) -> Model:
Expand All @@ -37,7 +39,8 @@ def read_schema(file: Union[str, PathLike, TextIO], include_common_registers: bo
with open(file) as fileIO:
return read_schema(fileIO)
else:
schema = parse_yaml_raw_as(Model, file.read())
raw_schema = yaml.safe_load(file.read())
schema = TypeAdapter(Model).validate_python(raw_schema)
if "WhoAmI" not in schema.registers and include_common_registers:
common = _read_common_registers()
schema.registers = dict(common.registers, **schema.registers)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ dynamic = ["version"]
license = "MIT"

dependencies = [
"pydantic-yaml",
"pydantic",
"pyyaml",
"pandas"
]

Expand Down
Loading