From 9a5feb373b2cededc054b06cdb55e5466c1d47ab Mon Sep 17 00:00:00 2001 From: banteg <4562643+banteg@users.noreply.github.com> Date: Thu, 21 Sep 2023 18:22:53 +0400 Subject: [PATCH] chore: relax pydantic dependency [APE-1373] (#54) --- .pre-commit-config.yaml | 6 +++--- evm_trace/_pydantic_compat.py | 7 +++++++ evm_trace/base.py | 2 +- evm_trace/geth.py | 2 +- evm_trace/parity.py | 3 +-- setup.py | 8 ++++---- tests/test_geth.py | 2 +- 7 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 evm_trace/_pydantic_compat.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3b35a00..bae32dc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 23.7.0 + rev: 23.9.1 hooks: - id: black name: black @@ -21,13 +21,13 @@ repos: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.1 + rev: v1.5.1 hooks: - id: mypy additional_dependencies: [types-PyYAML, types-requests, types-setuptools, pydantic] - repo: https://github.com/executablebooks/mdformat - rev: 0.7.16 + rev: 0.7.17 hooks: - id: mdformat additional_dependencies: [mdformat-gfm, mdformat-frontmatter] diff --git a/evm_trace/_pydantic_compat.py b/evm_trace/_pydantic_compat.py new file mode 100644 index 0000000..eda1190 --- /dev/null +++ b/evm_trace/_pydantic_compat.py @@ -0,0 +1,7 @@ +try: + from pydantic.v1 import Field, ValidationError, validator # type: ignore +except ImportError: + from pydantic import Field, ValidationError, validator # type: ignore + + +__all__ = ["Field", "validator", "ValidationError"] diff --git a/evm_trace/base.py b/evm_trace/base.py index ca74d97..c1765e6 100644 --- a/evm_trace/base.py +++ b/evm_trace/base.py @@ -3,8 +3,8 @@ from ethpm_types import BaseModel as _BaseModel from ethpm_types import HexBytes -from pydantic import validator +from evm_trace._pydantic_compat import validator from evm_trace.display import get_tree_display from evm_trace.enums import CallType diff --git a/evm_trace/geth.py b/evm_trace/geth.py index 6c9edb7..0771445 100644 --- a/evm_trace/geth.py +++ b/evm_trace/geth.py @@ -3,8 +3,8 @@ from eth_utils import to_int from ethpm_types import HexBytes -from pydantic import Field, validator +from evm_trace._pydantic_compat import Field, validator from evm_trace.base import BaseModel, CallTreeNode from evm_trace.enums import CALL_OPCODES, CallType from evm_trace.utils import to_address diff --git a/evm_trace/parity.py b/evm_trace/parity.py index 4a4ef52..6944f9d 100644 --- a/evm_trace/parity.py +++ b/evm_trace/parity.py @@ -1,7 +1,6 @@ from typing import Any, Dict, List, Optional, Union, cast -from pydantic import Field, validator - +from evm_trace._pydantic_compat import Field, validator from evm_trace.base import BaseModel, CallTreeNode from evm_trace.enums import CallType diff --git a/setup.py b/setup.py index 60afc92..f371e95 100644 --- a/setup.py +++ b/setup.py @@ -10,12 +10,12 @@ "eth-hash[pysha3]", # For eth-utils address checksumming ], "lint": [ - "black>=23.7.0,<24", # Auto-formatter and linter - "mypy>=1.4.1,<2", # Static type analyzer + "black>=23.9.1,<24", # Auto-formatter and linter + "mypy>=1.5.1,<2", # Static type analyzer "types-setuptools", # Needed for mypy type shed "flake8>=6.1.0,<7", # Style linter "isort>=5.10.1,<6", # Import sorting linter - "mdformat>=0.7.16", # Auto-formatter for markdown + "mdformat>=0.7.17", # Auto-formatter for markdown "mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown "mdformat-frontmatter>=0.4.1", # Needed for frontmatters-style headers in issue templates ], @@ -57,7 +57,7 @@ url="https://github.com/ApeWorX/evm-trace", include_package_data=True, install_requires=[ - "pydantic>=1.10.1,<2", + "pydantic>=1.10.1,<3", "py-evm>=0.7.0a3,<0.8", "eth-utils>=2.1,<3", "ethpm-types>=0.5.0,<0.6", diff --git a/tests/test_geth.py b/tests/test_geth.py index 5749640..0dfa65f 100644 --- a/tests/test_geth.py +++ b/tests/test_geth.py @@ -2,8 +2,8 @@ import pytest from ethpm_types import HexBytes -from pydantic import ValidationError +from evm_trace._pydantic_compat import ValidationError from evm_trace.enums import CallType from evm_trace.geth import ( TraceFrame,