Skip to content

Commit

Permalink
squash: add pydantic v2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
therazix committed Nov 5, 2024
1 parent 7e04e68 commit 9481860
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -241,6 +241,7 @@ ignore = [
"docs/**",
"examples/**",
"tests/**",
"tmt/_compat/pydantic.py",
"tmt/export/*.py",
"tmt/plugins/*.py",
"tmt/steps/*.py",
Expand Down Expand Up @@ -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"]

Expand Down
26 changes: 26 additions & 0 deletions tmt/_compat/pydantic.py
Original file line number Diff line number Diff line change
@@ -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",
]
2 changes: 1 addition & 1 deletion tmt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tmt/config/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, Extra
from tmt._compat.pydantic import BaseModel, Extra


def create_alias(name: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion tmt/config/models/link.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum

from pydantic import HttpUrl
from tmt._compat.pydantic import HttpUrl

from . import BaseConfig

Expand Down
2 changes: 1 addition & 1 deletion tmt/utils/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9481860

Please sign in to comment.