Skip to content
Closed
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
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ repos:
rev: 25.1.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.2.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.5
hooks:
- id: flake8
additional_dependencies:
- 'flake8-bugbear==24.4.26'
- 'flake8-typing-as-t==0.0.3'
- 'flake8-comprehensions==3.15.0'
- id: ruff
args: ["--fix"]
- repo: https://github.com/sirosen/slyp
rev: 0.8.2
hooks:
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ namespaces = false
[tool.isort]
profile = "black"

[tool.ruff]
select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"TYP", # flake8-typing-as-t
]

[tool.mypy]
# strict = true # TODO: enable
disallow_untyped_defs = true
Expand Down
4 changes: 2 additions & 2 deletions src/check_jsonschema/builtin_schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def _get(package: str, resource: str, name: str) -> dict[str, t.Any]:
importlib.resources.files(package).joinpath(resource).read_bytes()
),
)
except (FileNotFoundError, ModuleNotFoundError):
raise NoSuchSchemaError(f"no builtin schema named {name} was found")
except (FileNotFoundError, ModuleNotFoundError) as err:
raise NoSuchSchemaError(f"no builtin schema named {name} was found") from err


def _get_vendored_schema(name: str) -> dict[str, t.Any]:
Expand Down
14 changes: 9 additions & 5 deletions src/check_jsonschema/checker.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
from __future__ import annotations

import pathlib
import typing as t

import click
import jsonschema
import referencing.exceptions

from . import utils
from .formats import FormatOptions
from .instance_loader import InstanceLoader
from .parsers import ParseError
from .regex_variants import RegexImplementation
from .reporter import Reporter
from .result import CheckResult
from .schema_loader import SchemaLoaderBase, SchemaParseError, UnsupportedUrlScheme

Expand All @@ -22,6 +17,15 @@ def __init__(self, code: int) -> None:
self.code = code


if t.TYPE_CHECKING:
import pathlib

from .formats import FormatOptions
from .instance_loader import InstanceLoader
from .regex_variants import RegexImplementation
from .reporter import Reporter


class SchemaChecker:
def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/check_jsonschema/cli/main_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import typing as t

import click
import jsonschema
import jsonschema # noqa: TCH002

from ..catalog import CUSTOM_SCHEMA_NAMES, SCHEMA_CATALOG
from ..checker import SchemaChecker
Expand Down
7 changes: 5 additions & 2 deletions src/check_jsonschema/cli/parse_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import typing as t

import click
import jsonschema

from ..formats import FormatOptions
from ..regex_variants import RegexImplementation, RegexVariantName
from ..transforms import Transform

if t.TYPE_CHECKING:
import jsonschema

from ..transforms import Transform


class SchemaLoadingMode(enum.Enum):
Expand Down
3 changes: 2 additions & 1 deletion src/check_jsonschema/cli/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import typing as t
import warnings

import click
if t.TYPE_CHECKING:
import click


def deprecation_warning_callback(
Expand Down
5 changes: 4 additions & 1 deletion src/check_jsonschema/formats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from __future__ import annotations

import copy
import typing

import jsonschema
import jsonschema.validators

from ..regex_variants import RegexImplementation
from .implementations import validate_rfc3339, validate_time

if typing.TYPE_CHECKING:
from ..regex_variants import RegexImplementation

# all known format strings except for a selection from draft3 which have either
# been renamed or removed:
# - color
Expand Down
5 changes: 4 additions & 1 deletion src/check_jsonschema/identify_filetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

from __future__ import annotations

import pathlib
import typing

if typing.TYPE_CHECKING:
import pathlib

_EXTENSION_MAP = {
"json": "json",
Expand Down
8 changes: 5 additions & 3 deletions src/check_jsonschema/parsers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import annotations

import io
import pathlib
import typing as t

import ruamel.yaml

from ..identify_filetype import path_to_type
from . import json5, json_, toml, yaml

if t.TYPE_CHECKING:
import pathlib

import ruamel.yaml

_PARSER_ERRORS: set[type[Exception]] = {
json_.JSONDecodeError,
yaml.ParseError,
Expand Down
6 changes: 4 additions & 2 deletions src/check_jsonschema/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import click
import jsonschema

from .parsers import ParseError
from .result import CheckResult
from .utils import format_error, iter_validation_error

if t.TYPE_CHECKING:
from .parsers import ParseError
from .result import CheckResult


class Reporter(abc.ABC):
def __init__(self, *, verbosity: int, **kwargs: t.Any) -> None:
Expand Down
9 changes: 6 additions & 3 deletions src/check_jsonschema/result.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from __future__ import annotations

import pathlib
import typing

import jsonschema
if typing.TYPE_CHECKING:
import pathlib

from .parsers import ParseError
import jsonschema

from .parsers import ParseError


class CheckResult:
Expand Down
9 changes: 6 additions & 3 deletions src/check_jsonschema/schema_loader/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import functools
import pathlib
import typing as t
import urllib.error
import urllib.parse
Expand All @@ -11,12 +10,16 @@
from ..builtin_schemas import get_builtin_schema
from ..formats import FormatOptions, format_checker_for_regex_impl, make_format_checker
from ..parsers import ParserSet
from ..regex_variants import RegexImplementation
from ..utils import is_url_ish
from .errors import UnsupportedUrlScheme
from .readers import HttpSchemaReader, LocalSchemaReader, StdinSchemaReader
from .resolver import make_reference_registry

if t.TYPE_CHECKING:
import pathlib

from ..regex_variants import RegexImplementation


def _extend_with_default(
validator_class: type[jsonschema.protocols.Validator],
Expand Down Expand Up @@ -144,7 +147,7 @@ def get_validator(
) -> jsonschema.protocols.Validator:
return self._get_validator(format_opts, regex_impl, fill_defaults)

@functools.lru_cache
@functools.lru_cache # noqa: B019
def _get_validator(
self,
format_opts: FormatOptions,
Expand Down
4 changes: 3 additions & 1 deletion src/check_jsonschema/schema_loader/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from referencing.jsonschema import DRAFT202012, Schema

from ..cachedownloader import CacheDownloader
from ..parsers import ParserSet
from ..utils import filename2path

if t.TYPE_CHECKING:
from ..parsers import ParserSet


def make_reference_registry(
parsers: ParserSet, retrieval_uri: str | None, schema: dict, disable_cache: bool
Expand Down
4 changes: 3 additions & 1 deletion src/check_jsonschema/transforms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import typing

from .azure_pipelines import AZURE_TRANSFORM
from .base import Transform
from .base import Transform # noqa: TCH001
from .gitlab import GITLAB_TRANSFORM

TRANSFORM_LIBRARY: dict[str, Transform] = {
Expand Down
3 changes: 2 additions & 1 deletion src/check_jsonschema/transforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import typing as t

import ruamel.yaml
if t.TYPE_CHECKING:
import ruamel.yaml


class Transform:
Expand Down
5 changes: 3 additions & 2 deletions src/check_jsonschema/transforms/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import typing as t

import ruamel.yaml

from .base import Transform

if t.TYPE_CHECKING:
import ruamel.yaml


class GitLabReferenceExpectationViolation(ValueError):
def __init__(self, msg: str, data: t.Any) -> None:
Expand Down
4 changes: 3 additions & 1 deletion src/check_jsonschema/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import urllib.request

import click
import jsonschema

if t.TYPE_CHECKING:
import jsonschema

WINDOWS = os.name == "nt"

Expand Down
Loading