Skip to content

Commit

Permalink
Drop support python 3.7 on runtime (#2060)
Browse files Browse the repository at this point in the history
* Drop support python 3.7 on runtime

* Drop support python 3.7 on runtime

* remove unused code

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix imports

* Fix pydantic patch

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
koxudaxi and pre-commit-ci[bot] authored Aug 8, 2024
1 parent f7652d3 commit 04d6b03
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 199 deletions.
24 changes: 1 addition & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
isort-version: [4.3.21, 5.6.4]
black-version: [22.1.0, default]
Expand All @@ -39,16 +39,6 @@ jobs:
black-version: 23.12.1
python-version: 3.12
pydantic-version: 2.4.2
- os: macos-13
isort-version: 5.6.4
black-version: 22.1.0
python-version: 3.7
pydantic-version: 2.4.2
- os: macos-13
isort-version: 5.6.4
black-version: 22.1.0
python-version: 3.7
pydantic-version: 1.10.9
exclude:
- os: windows-latest
black-version: 22.1.0
Expand All @@ -58,8 +48,6 @@ jobs:
isort-version: 4.3.21
- os: macos-latest
isort-version: 4.3.21
- os: macos-latest
python-version: 3.7
- os: windows-latest
pydantic-version: 1.5.1
- os: macos-latest
Expand All @@ -85,18 +73,8 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install old Poetry
uses: snok/install-poetry@v1
if: matrix.python-version == '3.7'
with:
version: 1.4.2
virtualenvs-path: .venv
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Install Poetry
uses: snok/install-poetry@v1
if: matrix.python-version != '3.7'
with:
version: 1.7.1
virtualenvs-path: .venv
Expand Down
9 changes: 2 additions & 7 deletions datamodel_code_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,9 @@ def get_version() -> str: ...
def get_version() -> str:
package = 'datamodel-code-generator'

try:
from importlib.metadata import version

return version(package)
except ImportError:
import pkg_resources
from importlib.metadata import version

return pkg_resources.get_distribution(package).version
return version(package)


def enable_debug_message() -> None: # pragma: no cover
Expand Down
3 changes: 2 additions & 1 deletion datamodel_code_generator/pydantic_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ def patched_evaluate_forwardref(
)


if '3.12' in sys.version: # pragma: no cover
# Patch only Python3.12
if sys.version_info >= (3, 12):
pydantic.typing.evaluate_forwardref = patched_evaluate_forwardref
42 changes: 11 additions & 31 deletions datamodel_code_generator/util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from __future__ import annotations

import copy
from functools import cached_property # noqa: F401
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Dict, TypeVar
from typing import ( # noqa: F401
TYPE_CHECKING,
Any,
Callable,
Dict,
Protocol,
TypeVar,
runtime_checkable,
)

import pydantic
from packaging import version
Expand All @@ -15,46 +24,17 @@
PYDANTIC_V2: bool = PYDANTIC_VERSION >= version.parse('2.0b3')

if TYPE_CHECKING:
cached_property = property
from yaml import SafeLoader

Protocol = object
runtime_checkable: Callable[..., Any]

from typing_extensions import Literal
from yaml import SafeLoader

def load_toml(path: Path) -> Dict[str, Any]: ...

else:
try:
from typing import Protocol
except ImportError:
from typing_extensions import Protocol # noqa
try:
from typing import runtime_checkable
except ImportError:
from typing_extensions import runtime_checkable # noqa
try:
from yaml import CSafeLoader as SafeLoader
except ImportError: # pragma: no cover
from yaml import SafeLoader

try:
from functools import cached_property
except ImportError:
_NOT_FOUND = object()

class cached_property:
def __init__(self, func: Callable) -> None:
self.func: Callable = func
self.__doc__: Any = func.__doc__

def __get__(self, instance: Any, owner: Any = None) -> Any:
value = instance.__dict__.get(self.func.__name__, _NOT_FOUND)
if value is _NOT_FOUND: # pragma: no cover
value = instance.__dict__[self.func.__name__] = self.func(instance)
return value

try:
import tomllib

Expand Down
Loading

0 comments on commit 04d6b03

Please sign in to comment.