From 58905c0ad387d2f67a700ba79cec37cf4eb2cce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20V=C3=A1gner?= Date: Tue, 5 Nov 2024 18:13:25 +0100 Subject: [PATCH] squash: add pydantic v2 compatibility --- .pre-commit-config.yaml | 6 +++--- pyproject.toml | 7 ++++++- tmt/_compat/pydantic.py | 26 ++++++++++++++++++++++++++ tmt/config/__init__.py | 2 +- tmt/config/models/__init__.py | 2 +- tmt/config/models/link.py | 2 +- tmt/utils/jira.py | 2 +- 7 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 tmt/_compat/pydantic.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 88f6566fb1..e6d299e6ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,7 +38,7 @@ repos: - "jinja2>=2.11.3" # 3.1.2 / 3.1.2 - "packaging>=20" # 20 seems to be available with RHEL8 - "pint>=0.16.1" # 0.16.1 - - "pydantic>=1.10, <2.0" + - "pydantic>=1.10.14" - "pygments>=2.7.4" # 2.7.4 is the current one available for RHEL9 - "requests>=2.25.1" # 2.28.2 / 2.31.0 - "ruamel.yaml>=0.16.6" # 0.17.32 / 0.17.32 @@ -87,7 +87,7 @@ repos: - "jinja2>=2.11.3" # 3.1.2 / 3.1.2 - "packaging>=20" # 20 seems to be available with RHEL8 - "pint>=0.16.1" # 0.16.1 / 0.19.x TODO: Pint 0.20 requires larger changes to tmt.hardware - - "pydantic>=1.10, <2.0" + - "pydantic>=1.10.14" - "pygments>=2.7.4" # 2.7.4 is the current one available for RHEL9 - "requests>=2.25.1" # 2.28.2 / 2.31.0 - "ruamel.yaml>=0.16.6" # 0.17.32 / 0.17.32 @@ -160,7 +160,7 @@ repos: - "docutils>=0.16" # 0.16 is the current one available for RHEL9 - "packaging>=20" # 20 seems to be available with RHEL8 - "pint<0.20" - - "pydantic>=1.10, <2.0" + - "pydantic>=1.10.14" - "pygments>=2.7.4" # 2.7.4 is the current one available for RHEL9 # Help installation by reducing the set of inspected botocore release. # There is *a lot* of them, and hatch might fetch many of them. diff --git a/pyproject.toml b/pyproject.toml index 380b6bf946..7a67a398ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ dependencies = [ # F39 / PyPI "jinja2>=2.11.3", # 3.1.2 / 3.1.2 "packaging>=20", # 20 seems to be available with RHEL8 "pint>=0.16.1", # 0.16.1 - "pydantic>=1.10, <2.0", + "pydantic>=1.10.14", "pygments>=2.7.4", # 2.7.4 is the current one available for RHEL9 "requests>=2.25.1", # 2.28.2 / 2.31.0 "ruamel.yaml>=0.16.6", # 0.17.32 / 0.17.32 @@ -241,6 +241,7 @@ ignore = [ "docs/**", "examples/**", "tests/**", + "tmt/_compat/pydantic.py", "tmt/export/*.py", "tmt/plugins/*.py", "tmt/steps/*.py", @@ -412,11 +413,15 @@ builtins-ignorelist = ["help", "format", "input", "filter", "copyright", "max"] "typing_extensions.Self".msg = "Use tmt._compat.typing.Self instead." "pathlib.Path".msg = "Use tmt._compat.pathlib.Path instead." "pathlib.PosixPath".msg = "Use tmt._compat.pathlib.Path instead." +"pydantic".msg = "Use tmt._compat.pydantic instead." "warnings.deprecated".msg = "Use tmt._compat.warnings.deprecated instead." "os.path".msg = "Use tmt._compat.pathlib.Path and pathlib instead." # Banning builtins is not yet supported: https://github.com/astral-sh/ruff/issues/10079 # "builtins.open".msg = "Use Path.{write_text,append_text,read_text,write_bytes,read_bytes} instead." +[tool.ruff.lint.flake8-type-checking] +runtime-evaluated-base-classes = ["tmt.config.models.BaseConfig"] + [tool.ruff.lint.isort] known-first-party = ["tmt"] diff --git a/tmt/_compat/pydantic.py b/tmt/_compat/pydantic.py new file mode 100644 index 0000000000..b4608347f0 --- /dev/null +++ b/tmt/_compat/pydantic.py @@ -0,0 +1,26 @@ +# mypy: disable-error-code="assignment" +from __future__ import annotations + +import pydantic + +if pydantic.__version__.startswith('1.'): + from pydantic import ( + BaseModel, + Extra, + HttpUrl, + ValidationError, + ) +else: + from pydantic.v1 import ( + BaseModel, + Extra, + HttpUrl, + ValidationError, + ) + +__all__ = [ + "BaseModel", + "Extra", + "HttpUrl", + "ValidationError", + ] diff --git a/tmt/config/__init__.py b/tmt/config/__init__.py index adbff3d4c1..3fa118b39e 100644 --- a/tmt/config/__init__.py +++ b/tmt/config/__init__.py @@ -5,10 +5,10 @@ import fmf import fmf.utils -from pydantic import ValidationError import tmt.utils from tmt._compat.pathlib import Path +from tmt._compat.pydantic import ValidationError from tmt.config.models.link import LinkConfig # Config directory diff --git a/tmt/config/models/__init__.py b/tmt/config/models/__init__.py index a7dbb88727..6a1635216f 100644 --- a/tmt/config/models/__init__.py +++ b/tmt/config/models/__init__.py @@ -1,4 +1,4 @@ -from pydantic import BaseModel, Extra +from tmt._compat.pydantic import BaseModel, Extra def create_alias(name: str) -> str: diff --git a/tmt/config/models/link.py b/tmt/config/models/link.py index 27d8a5b324..06b82e07ce 100644 --- a/tmt/config/models/link.py +++ b/tmt/config/models/link.py @@ -1,6 +1,6 @@ from enum import Enum -from pydantic import HttpUrl +from tmt._compat.pydantic import HttpUrl from . import BaseConfig diff --git a/tmt/utils/jira.py b/tmt/utils/jira.py index b657934f53..13df0aa457 100644 --- a/tmt/utils/jira.py +++ b/tmt/utils/jira.py @@ -89,7 +89,7 @@ def from_issue_url( continue # Issue url must match - if issue_url.startswith(issue_tracker.url): + if issue_url.startswith(str(issue_tracker.url)): return JiraInstance(issue_tracker, logger=logger) return None