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

Use referencing library where available instead of deprecated jsonschema.RefResolver #253

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

martinhoyer
Copy link
Contributor

@martinhoyer martinhoyer commented Aug 27, 2024

Addressing #194

The deprecation warnings everywhere are getting too annoying to ignore :)

@martinhoyer martinhoyer added utils and removed discuss labels Nov 1, 2024
@martinhoyer martinhoyer changed the title [DO NOT MERGE] Migrate from RefResolver to referencing library Use referencing library where available instead of deprecated jsonschema.RefResolver Nov 1, 2024
@martinhoyer martinhoyer marked this pull request as ready for review November 1, 2024 19:13
@@ -34,6 +34,7 @@ BuildRequires: python%{python3_pkgversion}-jsonschema
BuildRequires: git-core
%{?python_provide:%python_provide python%{python3_pkgversion}-%{name}}
Requires: git-core
Recommends: python%{python3_pkgversion}-referencing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need it. The dependency is part of jsonschema as early as 4.18 1 and for rhel case we can just assume it does not have the interface.

Footnotes

  1. https://github.com/python-jsonschema/jsonschema/commit/69f3899c0770472f19898d80aea2b7a51fd5ec6b

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh cool, thanks. Removing.


if MODERN_JSONSCHEMA:
# Modern approach with referencing
registry: Registry = Registry().with_resources([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
registry: Registry = Registry().with_resources([
registry = Registry().with_resources([

Should not be necessary

Comment on lines +10 to +16
try:
from jsonschema import validators
from referencing import Registry, create
from referencing.jsonschema import DRAFT4
MODERN_JSONSCHEMA = True
except ImportError:
MODERN_JSONSCHEMA = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make the test be on the importlib package version instead? It is less clear what MODERN_JSONSCHEMA is referring to otherwise. As for the create_validator, what about adding the imports in there?

Comment on lines +3 to +6
from __future__ import annotations

import warnings
from typing import Any, Dict, List, NamedTuple, Optional, Union
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not mix __future__.annotation and typing.Dict for now. We should take a hammer at it eventually though.

Comment on lines +19 to +22
class JsonSchemaValidationResult(NamedTuple):
"""Represents JSON Schema validation result."""
result: bool
errors: List[Any]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these should be in a _compat package. Maybe utils.jsonschema instead. For this PR though, we can keep them in the original place.

Comment on lines +42 to +43
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try without the catch_warnings. There should not be the DeprecationWarning being triggered if the MODERN_JSONSCHEMA is working appropriately, and if it does, we should investigate why it does.

Comment on lines +25 to +29
def create_validator(
schema: Dict[str, Any],
schema_store: Optional[Dict[str, Any]] = None
) -> Union[jsonschema.validators.Validator, jsonschema.validators.Draft4Validator]:
"""Create a validator instance based on available jsonschema version."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am more used to create naming convention being a static/classmethod. Just a thought if it should be get or create or something else.

Comment on lines +22 to +23
from fmf._compat_jsonschema import JsonSchemaValidationResult # noqa: F401
from fmf._compat_jsonschema import validate_data # noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn't fmf._compat.jsonschema work?

@@ -419,7 +422,7 @@ class Logging:
_level = LOG_WARN

# Already initialized loggers by their name
_loggers = dict()
_loggers: dict[str, logging.Logger] = dict()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't have __future__.annotations here so it should be using Dict instead here. But also let's deffer the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants