Minor fixes.
Labeler / labeler (push) Has been cancelled
Release / Release (push) Has been cancelled
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (macos-latest, 3.9, tests) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.6, mypy) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.6, tests) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.7, mypy) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.7, tests) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.8, docs-build) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.8, mypy) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.8, tests) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, mypy) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, pre-commit) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, safety) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, tests) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, typeguard) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, xdoctest) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (windows-latest, 3.9, tests) (push) Waiting to run
Tests / coverage (push) Blocked by required conditions
Labeler / labeler (push) Has been cancelled
Release / Release (push) Has been cancelled
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (macos-latest, 3.9, tests) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.6, mypy) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.6, tests) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.7, mypy) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.7, tests) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.8, docs-build) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.8, mypy) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.8, tests) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, mypy) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, pre-commit) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, safety) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, tests) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, typeguard) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (ubuntu-latest, 3.9, xdoctest) (push) Waiting to run
Tests / ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }} (windows-latest, 3.9, tests) (push) Waiting to run
Tests / coverage (push) Blocked by required conditions
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
@@ -23,14 +23,15 @@ __all__ = ["get", "modify"]
|
|||||||
class YamlData(base.BaseData):
|
class YamlData(base.BaseData):
|
||||||
"""Base class for strictyaml classes."""
|
"""Base class for strictyaml classes."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod # type: ignore [misc]
|
||||||
|
@property
|
||||||
@functools.cache
|
@functools.cache
|
||||||
def strictyaml_schema(cls: type[YamlData]) -> strictyaml.Map:
|
def strictyaml_schema(cls: type[YamlData]) -> strictyaml.Map:
|
||||||
"""Get the strictyaml schema for this class."""
|
"""Get the strictyaml schema for this class."""
|
||||||
field_map = {}
|
field_map = {}
|
||||||
for field in dataclasses.fields(cls):
|
for field in dataclasses.fields(cls):
|
||||||
try:
|
try:
|
||||||
field_map[field.name] = globals()[field.type].strictyaml_schema()
|
field_map[field.name] = globals()[field.type].strictyaml_schema
|
||||||
except (KeyError, AttributeError):
|
except (KeyError, AttributeError):
|
||||||
match field.type:
|
match field.type:
|
||||||
case "int":
|
case "int":
|
||||||
@@ -135,9 +136,12 @@ class Settings(YamlData):
|
|||||||
filepath: pathlib.Path,
|
filepath: pathlib.Path,
|
||||||
) -> Settings:
|
) -> Settings:
|
||||||
"""Read the given YAML file and convert it into an object."""
|
"""Read the given YAML file and convert it into an object."""
|
||||||
with filepath.open() as fp:
|
try:
|
||||||
yaml_data = strictyaml.load(fp.read(), cls.strictyaml_schema())
|
with filepath.open() as fp:
|
||||||
return typing.cast(Settings, cls.load(yaml_data.data))
|
yaml_data = strictyaml.load(fp.read(), cls.strictyaml_schema)
|
||||||
|
return typing.cast(Settings, cls.load(yaml_data.data))
|
||||||
|
except strictyaml.YAMLValidationError:
|
||||||
|
return cls.yaml_create(filepath)
|
||||||
|
|
||||||
def yaml_write(self: Settings, filepath: pathlib.Path) -> None:
|
def yaml_write(self: Settings, filepath: pathlib.Path) -> None:
|
||||||
"""Write this object as the given YAML file."""
|
"""Write this object as the given YAML file."""
|
||||||
|
|||||||
Reference in New Issue
Block a user