Minor fixes.
Some checks failed
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
Some checks failed
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):
|
||||
"""Base class for strictyaml classes."""
|
||||
|
||||
@classmethod
|
||||
@classmethod # type: ignore [misc]
|
||||
@property
|
||||
@functools.cache
|
||||
def strictyaml_schema(cls: type[YamlData]) -> strictyaml.Map:
|
||||
"""Get the strictyaml schema for this class."""
|
||||
field_map = {}
|
||||
for field in dataclasses.fields(cls):
|
||||
try:
|
||||
field_map[field.name] = globals()[field.type].strictyaml_schema()
|
||||
field_map[field.name] = globals()[field.type].strictyaml_schema
|
||||
except (KeyError, AttributeError):
|
||||
match field.type:
|
||||
case "int":
|
||||
@@ -135,9 +136,12 @@ class Settings(YamlData):
|
||||
filepath: pathlib.Path,
|
||||
) -> Settings:
|
||||
"""Read the given YAML file and convert it into an object."""
|
||||
with filepath.open() as fp:
|
||||
yaml_data = strictyaml.load(fp.read(), cls.strictyaml_schema())
|
||||
return typing.cast(Settings, cls.load(yaml_data.data))
|
||||
try:
|
||||
with filepath.open() as fp:
|
||||
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:
|
||||
"""Write this object as the given YAML file."""
|
||||
|
||||
Reference in New Issue
Block a user