Skip to content
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
15 changes: 7 additions & 8 deletions src/poetry/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

import json

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

import fastjsonschema

from fastjsonschema.exceptions import JsonSchemaValueException
from poetry.core.json import SCHEMA_DIR as CORE_SCHEMA_DIR


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


def validate_object(obj: dict[str, Any]) -> list[str]:
schema_file = Path(SCHEMA_DIR, "poetry.json")
schema = json.loads(schema_file.read_text(encoding="utf-8"))
schema = json.loads(
(files(__package__) / "schemas" / "poetry.json").read_text(encoding="utf-8")
)

validate = fastjsonschema.compile(schema)

Expand All @@ -27,7 +24,9 @@ def validate_object(obj: dict[str, Any]) -> list[str]:
errors = [e.message]

core_schema = json.loads(
(CORE_SCHEMA_DIR / "poetry-schema.json").read_text(encoding="utf-8")
(files("poetry.core") / "json" / "schemas" / "poetry-schema.json").read_text(
encoding="utf-8"
)
)

properties = schema["properties"].keys() | core_schema["properties"].keys()
Expand Down
11 changes: 6 additions & 5 deletions tests/json/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import json

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

from poetry.core.json import SCHEMA_DIR as CORE_SCHEMA_DIR

from poetry.factory import Factory
from poetry.json import SCHEMA_DIR
from poetry.toml import TOMLFile


SCHEMA_FILE = files("poetry.json") / "schemas" / "poetry.json"
FIXTURE_DIR = Path(__file__).parent / "fixtures"
SOURCE_FIXTURE_DIR = FIXTURE_DIR / "source"

Expand Down Expand Up @@ -59,12 +58,14 @@ def test_self_invalid_plugin() -> None:


def test_dependencies_is_consistent_to_poetry_core_schema() -> None:
with (SCHEMA_DIR / "poetry.json").open(encoding="utf-8") as f:
with SCHEMA_FILE.open(encoding="utf-8") as f:
schema = json.load(f)
dependency_definitions = {
key: value for key, value in schema["definitions"].items() if "depend" in key
}
with (CORE_SCHEMA_DIR / "poetry-schema.json").open(encoding="utf-8") as f:
with (files("poetry.core") / "json" / "schemas" / "poetry-schema.json").open(
encoding="utf-8"
) as f:
core_schema = json.load(f)
core_dependency_definitions = {
key: value
Expand Down