Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: re-organize schema module #172

Merged
merged 2 commits into from
Apr 21, 2024
Merged
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
24 changes: 19 additions & 5 deletions src/anyconfig/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@
# Copyright (C) 2021 - 2024 Satoru SATOH <satoru.satoh gmail.com>
# SPDX-License-Identifier: MIT
#
"""Misc global constants, variables, classes and so on."""
"""Schema generation and validation."""
from __future__ import annotations

from .jsonschema.generator import gen_schema

try:
from .jsonschema import validate, is_valid, gen_schema
from .jsonschema.validator import validate, is_valid

VALIDATORS = {
"jsonschema": validate
}
SUPPORTED: bool = True
except ImportError:
from .default import validate, is_valid, gen_schema
from .default import validate, is_valid # noqa: F401
VALIDATORS = {}
SUPPORTED = False


__all__ = [
"validate", "is_valid", "gen_schema", "SUPPORTED"
GENERATORS = {
"jsonschema": gen_schema
}

_all__ = [
"validate", "is_valid", "gen_schema",
"VALIDATORS", "GENERATORS", "SUPPORTED"
]
5 changes: 5 additions & 0 deletions src/anyconfig/schema/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
# Copyright (C) 2021 - 2024 Satoru SATOH <satoru.satoh gmail.com>
# SPDX-License-Identifier: MIT
#
# pylint: disable=unused-import
"""Some common constants, utility functions and so on."""
from __future__ import annotations

import typing

from ..common import ( # noqa: F401
ValidationError, InDataT, InDataExT
)


ResultT = tuple[bool, typing.Union[str, list[str]]]
9 changes: 5 additions & 4 deletions src/anyconfig/schema/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

import typing

from .jsonschema import generator

if typing.TYPE_CHECKING:
from ..common import (
InDataT, InDataExT
from .datatypes import (
InDataT, InDataExT, ResultT
)
from .datatypes import ResultT


def validate(
Expand All @@ -35,4 +36,4 @@ def is_valid(

def gen_schema(data: InDataExT, **options) -> InDataT:
"""Provide a dummy function generates an empty dict in actual."""
return {}
return generator.gen_schema(data, **options)
241 changes: 0 additions & 241 deletions src/anyconfig/schema/jsonschema.py

This file was deleted.

1 change: 1 addition & 0 deletions src/anyconfig/schema/jsonschema/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""jsonschema generator and validator."""
Loading