Skip to content

Commit 9481860

Browse files
committed
squash: add pydantic v2 compatibility
1 parent 7e04e68 commit 9481860

File tree

7 files changed

+39
-8
lines changed

7 files changed

+39
-8
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ repos:
3838
- "jinja2>=2.11.3" # 3.1.2 / 3.1.2
3939
- "packaging>=20" # 20 seems to be available with RHEL8
4040
- "pint>=0.16.1" # 0.16.1
41-
- "pydantic>=1.10, <2.0"
41+
- "pydantic>=1.10.14"
4242
- "pygments>=2.7.4" # 2.7.4 is the current one available for RHEL9
4343
- "requests>=2.25.1" # 2.28.2 / 2.31.0
4444
- "ruamel.yaml>=0.16.6" # 0.17.32 / 0.17.32
@@ -87,7 +87,7 @@ repos:
8787
- "jinja2>=2.11.3" # 3.1.2 / 3.1.2
8888
- "packaging>=20" # 20 seems to be available with RHEL8
8989
- "pint>=0.16.1" # 0.16.1 / 0.19.x TODO: Pint 0.20 requires larger changes to tmt.hardware
90-
- "pydantic>=1.10, <2.0"
90+
- "pydantic>=1.10.14"
9191
- "pygments>=2.7.4" # 2.7.4 is the current one available for RHEL9
9292
- "requests>=2.25.1" # 2.28.2 / 2.31.0
9393
- "ruamel.yaml>=0.16.6" # 0.17.32 / 0.17.32
@@ -160,7 +160,7 @@ repos:
160160
- "docutils>=0.16" # 0.16 is the current one available for RHEL9
161161
- "packaging>=20" # 20 seems to be available with RHEL8
162162
- "pint<0.20"
163-
- "pydantic>=1.10, <2.0"
163+
- "pydantic>=1.10.14"
164164
- "pygments>=2.7.4" # 2.7.4 is the current one available for RHEL9
165165
# Help installation by reducing the set of inspected botocore release.
166166
# There is *a lot* of them, and hatch might fetch many of them.

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies = [ # F39 / PyPI
3636
"jinja2>=2.11.3", # 3.1.2 / 3.1.2
3737
"packaging>=20", # 20 seems to be available with RHEL8
3838
"pint>=0.16.1", # 0.16.1
39-
"pydantic>=1.10, <2.0",
39+
"pydantic>=1.10.14",
4040
"pygments>=2.7.4", # 2.7.4 is the current one available for RHEL9
4141
"requests>=2.25.1", # 2.28.2 / 2.31.0
4242
"ruamel.yaml>=0.16.6", # 0.17.32 / 0.17.32
@@ -241,6 +241,7 @@ ignore = [
241241
"docs/**",
242242
"examples/**",
243243
"tests/**",
244+
"tmt/_compat/pydantic.py",
244245
"tmt/export/*.py",
245246
"tmt/plugins/*.py",
246247
"tmt/steps/*.py",
@@ -412,11 +413,15 @@ builtins-ignorelist = ["help", "format", "input", "filter", "copyright", "max"]
412413
"typing_extensions.Self".msg = "Use tmt._compat.typing.Self instead."
413414
"pathlib.Path".msg = "Use tmt._compat.pathlib.Path instead."
414415
"pathlib.PosixPath".msg = "Use tmt._compat.pathlib.Path instead."
416+
"pydantic".msg = "Use tmt._compat.pydantic instead."
415417
"warnings.deprecated".msg = "Use tmt._compat.warnings.deprecated instead."
416418
"os.path".msg = "Use tmt._compat.pathlib.Path and pathlib instead."
417419
# Banning builtins is not yet supported: https://github.com/astral-sh/ruff/issues/10079
418420
# "builtins.open".msg = "Use Path.{write_text,append_text,read_text,write_bytes,read_bytes} instead."
419421

422+
[tool.ruff.lint.flake8-type-checking]
423+
runtime-evaluated-base-classes = ["tmt.config.models.BaseConfig"]
424+
420425
[tool.ruff.lint.isort]
421426
known-first-party = ["tmt"]
422427

tmt/_compat/pydantic.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# mypy: disable-error-code="assignment"
2+
from __future__ import annotations
3+
4+
import pydantic
5+
6+
if pydantic.__version__.startswith('1.'):
7+
from pydantic import (
8+
BaseModel,
9+
Extra,
10+
HttpUrl,
11+
ValidationError,
12+
)
13+
else:
14+
from pydantic.v1 import (
15+
BaseModel,
16+
Extra,
17+
HttpUrl,
18+
ValidationError,
19+
)
20+
21+
__all__ = [
22+
"BaseModel",
23+
"Extra",
24+
"HttpUrl",
25+
"ValidationError",
26+
]

tmt/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import fmf
77
import fmf.utils
8-
from pydantic import ValidationError
98

109
import tmt.utils
1110
from tmt._compat.pathlib import Path
11+
from tmt._compat.pydantic import ValidationError
1212
from tmt.config.models.link import LinkConfig
1313

1414
# Config directory

tmt/config/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic import BaseModel, Extra
1+
from tmt._compat.pydantic import BaseModel, Extra
22

33

44
def create_alias(name: str) -> str:

tmt/config/models/link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from enum import Enum
22

3-
from pydantic import HttpUrl
3+
from tmt._compat.pydantic import HttpUrl
44

55
from . import BaseConfig
66

tmt/utils/jira.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def from_issue_url(
8989
continue
9090

9191
# Issue url must match
92-
if issue_url.startswith(issue_tracker.url):
92+
if issue_url.startswith(str(issue_tracker.url)):
9393
return JiraInstance(issue_tracker, logger=logger)
9494

9595
return None

0 commit comments

Comments
 (0)