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

Cleanup json schema validation #819

Merged
merged 1 commit into from
Feb 1, 2025
Merged
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
15 changes: 1 addition & 14 deletions src/poetry/core/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,19 @@
import json

from importlib.resources import files
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any

import fastjsonschema

from fastjsonschema.exceptions import JsonSchemaException


if TYPE_CHECKING:
from importlib.abc import Traversable


SCHEMA_DIR = Path(__file__).parent / "schemas"


def _get_schema_file(schema_name: str) -> Traversable:
return files(__package__) / "schemas" / f"{schema_name}.json"


class ValidationError(ValueError):
pass


def validate_object(obj: dict[str, Any], schema_name: str) -> list[str]:
schema_file = _get_schema_file(schema_name)
schema_file = files(__package__) / "schemas" / f"{schema_name}.json"

if not schema_file.is_file():
raise ValueError(f"Schema {schema_name} does not exist.")
Expand Down