Switch from pykwalify to yamale

This commit is contained in:
Gürkan 2023-12-18 23:10:06 +01:00
parent ee2c1b9f0b
commit 4eebc186a6
4 changed files with 27 additions and 95 deletions

View File

@ -1,85 +1,20 @@
type: map
mapping:
global_failback:
type: map
mapping:
regex;(.*):
type: map
required: False
mapping:
primary:
type: bool
required: False
frequency:
type: int
required: False
resolution:
type: str
pattern: "^[0-9]+x[0-9]+$"
required: False
left-of:
type: str
required: False
right-of:
type: str
required: False
above:
type: str
required: False
below:
type: str
required: False
rotate:
type: str
enum:
- "normal"
- "left"
- "right"
- "inverted"
required: False
on_screen_count:
type: map
allowempty: True
matching-rule: all
mapping:
regex;(^\d+$):
type: seq
sequence:
- type: map
allowempty: True
matching-rule: all
mapping:
regex;([.*]?): # Basically any key
type: map
allowempty: True
mapping:
primary:
type: bool
required: False
frequency:
type: int
required: False
resolution:
type: str
pattern: "^[0-9]+x[0-9]+$"
required: False
left-of:
type: str
required: False
right-of:
type: str
required: False
above:
type: str
required: False
below:
type: str
required: False
rotate:
type: str
enum:
- "normal"
- "left"
- "right"
- "inverted"
required: False
# schema.yaml
on_screen_count: map(list(include('screen_config')), key=int())
global_failback: map(include('device'), key=str())
---
screen_config:
map(any(include('device'), include('hooks')), key=str(), required=False)
device:
resolution: str(required=False)
frequency: int(required=False)
primary: bool(required=False)
left-of: str(required=False)
disabled: bool(required=False)
hooks:
post: list(str(), required=False)
pre: list(str(), required=False)

View File

@ -6,6 +6,7 @@ import logging
import pickle
import sys
import subprocess
import yamale
from shutil import which
from copy import deepcopy
from collections import defaultdict
@ -20,7 +21,6 @@ from os.path import (
)
from pathlib import Path
from pprint import pprint
from pykwalify.core import Core
from typing import (
Dict,
List,
@ -269,18 +269,15 @@ def validate_config(config: Dict, logger: logging.Logger):
current_folder = dirname(abspath(__file__))
schema_file = path_join(current_folder, 'config_schema.yaml')
core = Core(source_data=config, schema_files=[schema_file])
# Prevent pykwalify from printing to stdout itself
logging.getLogger('pykwalify.core').handlers = [logging.NullHandler()]
schema = yamale.make_schema(schema_file)
data = yamale.make_data(CONFIG_FILE)
try:
core.validate(raise_exception=True)
yamale.validate(schema, data)
assert_unique_primary(config)
logger.debug('Validation of configuration successful.')
except Exception as e:
logger.error('Validation of configuration failed. Details:')
pprint(e.args[0], width=get_terminal_size().columns)
print(str(e))
exit(1)

View File

@ -9,9 +9,9 @@ python = "^3.10"
typing-extensions = "^4.4.0"
jc = "^1.23.6"
pyyaml = "^6.0.1"
pykwalify = "^1.8.0"
xdg-base-dirs = "^6.0.1"
pyedid = "^1.0.3"
yamale = "^4.0.4"
[tool.poetry.dev-dependencies]

View File

@ -20,7 +20,7 @@ pkgs.mkShell {
propagatedBuildInputs = with python.pkgs; [
jc
pyyaml
pykwalify
yamale
xdg-base-dirs
];
}