From 8fd4bb041014c32acd116e2710f296bb675a21d5 Mon Sep 17 00:00:00 2001 From: Pavel Mosein Date: Sun, 24 Mar 2024 16:25:02 +0500 Subject: [PATCH 1/8] Add python3.12 --- .github/workflows/lint.yml | 8 ++++---- .github/workflows/publish.yml | 4 ++-- .github/workflows/test.yml | 1 + pyproject.toml | 10 ++++++---- tox.ini | 17 ++++++++++------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 66dad61..c533648 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup python3.11 + - name: Setup python3.12 uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: '3.12' - run: python -m pip install poetry==1.6 - run: poetry install - run: poetry run ruff simdjson_schemaful tests @@ -27,10 +27,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup python3.8 + - name: Setup python3.12 uses: actions/setup-python@v4 with: - python-version: '3.8' + python-version: '3.12' - run: python -m pip install poetry==1.6 - run: poetry install - run: poetry run tox -m mypy diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 37fc080..96555d5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,10 +13,10 @@ jobs: contents: read steps: - uses: actions/checkout@v4 - - name: Setup python3.11 + - name: Setup python3.12 uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: '3.12' - name: Install poetry run: python -m pip install poetry diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4761544..ad8c884 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,7 @@ jobs: - '3.9' - '3.10' - '3.11' + - '3.12' steps: - uses: actions/checkout@v4 - name: Setup python${{ matrix.python }} diff --git a/pyproject.toml b/pyproject.toml index c268db4..a6e522a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python", "Topic :: Internet", @@ -46,12 +47,13 @@ name = "pypi" priority = "primary" [tool.poetry.dependencies] -python = ">=3.8,<3.12" +python = ">=3.8,<3.13" pysimdjson = [ - {version=">=2,<6", python=">=3.8,<3.9"}, - {version=">=3,<6", python=">=3.9,<3.11"}, + {version=">=2,<7", python=">=3.8,<3.9"}, + {version=">=3,<7", python=">=3.9,<3.11"}, # version 4 does not build for 3.11 for some reason - {version=">=3,!=4.*,<6", python=">=3.11,<3.12"}, + {version=">=3,!=4.*,<7", python=">=3.11,<3.12"}, + {version=">=6,<7", python=">=3.12,<3.13"}, ] pydantic = { version = ">=1,<3", optional = true } diff --git a/tox.ini b/tox.ini index dfc8386..94f5e35 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,17 @@ [tox] isolated_build = True -envlist = py{38}-pydantic{1,2}-pysimdjson{2,3,4,5},\ - py{39,310}-pydantic{1,2}-pysimdjson{3,4,5},\ - py{311}-pydantic{1,2}-pysimdjson{3,5} +envlist = py{38}-pydantic{1,2}-pysimdjson{2,3,4,5,6},\ + py{39,310}-pydantic{1,2}-pysimdjson{3,4,5,6},\ + py{311}-pydantic{1,2}-pysimdjson{3,5,6},\ + py{312}-pydantic{1,2}-pysimdjson{6} toxworkdir = {env:TOXDIR:.tox} labels = - py38 = py38-pydantic{1,2}-pysimdjson{2,3,4,5} - py39 = py39-pydantic{1,2}-pysimdjson{3,4,5} - py310 = py310-pydantic{1,2}-pysimdjson{3,4,5} - py311 = py311-pydantic{1,2}-pysimdjson{3,5} + py38 = py38-pydantic{1,2}-pysimdjson{2,3,4,5,6} + py39 = py39-pydantic{1,2}-pysimdjson{3,4,5,6} + py310 = py310-pydantic{1,2}-pysimdjson{3,4,5,6} + py311 = py311-pydantic{1,2}-pysimdjson{3,5,6} + py312 = py312-pydantic{1,2}-pysimdjson{3,5,6} [testenv] passenv= @@ -26,6 +28,7 @@ deps = pysimdjson3: pysimdjson~=3.0 pysimdjson4: pysimdjson~=4.0 pysimdjson5: pysimdjson~=5.0 + pysimdjson6: pysimdjson~=6.0 commands = pytest tests From 37bde75987a6dd54427724d2b13a5d71986e9cf0 Mon Sep 17 00:00:00 2001 From: Nikitin Artyom Date: Sun, 24 Mar 2024 18:27:03 +0300 Subject: [PATCH 2/8] Update tox.ini --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 94f5e35..c9f5aed 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,7 @@ labels = py39 = py39-pydantic{1,2}-pysimdjson{3,4,5,6} py310 = py310-pydantic{1,2}-pysimdjson{3,4,5,6} py311 = py311-pydantic{1,2}-pysimdjson{3,5,6} - py312 = py312-pydantic{1,2}-pysimdjson{3,5,6} + py312 = py312-pydantic{1,2}-pysimdjson{6} [testenv] passenv= From 3f5b405c8c48c5ccd3196e4f1e6e7b6c276c1ca4 Mon Sep 17 00:00:00 2001 From: Pavel Mosein Date: Sun, 24 Mar 2024 20:43:24 +0500 Subject: [PATCH 3/8] Fix tests for cp312 --- .github/workflows/lint.yml | 2 +- simdjson_schemaful/pydantic/v2.py | 18 ++++++++++++------ tox.ini | 6 +++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c533648..c8115d0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -30,7 +30,7 @@ jobs: - name: Setup python3.12 uses: actions/setup-python@v4 with: - python-version: '3.12' + python-version: '3.11' - run: python -m pip install poetry==1.6 - run: poetry install - run: poetry run tox -m mypy diff --git a/simdjson_schemaful/pydantic/v2.py b/simdjson_schemaful/pydantic/v2.py index 948166f..cee2481 100644 --- a/simdjson_schemaful/pydantic/v2.py +++ b/simdjson_schemaful/pydantic/v2.py @@ -1,5 +1,5 @@ import json -from typing import TYPE_CHECKING, Any, Dict, Optional, Type, TypeVar, Union +from typing import Any, Dict, Generic, Optional, TYPE_CHECKING, Type, TypeVar, Union import pydantic from pydantic import ValidationError @@ -38,10 +38,16 @@ def model_validate_simdjson( return cls.model_validate(obj) -class TypeAdapter(pydantic.TypeAdapter[T]): +class TypeAdapter(Generic[T]): + __slots__ = ("_ta", "_simdjson_schema") + def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - self._simdjson_schema = self.json_schema() + self._ta = pydantic.TypeAdapter[T](*args, **kwargs) + self._simdjson_schema = self._ta.json_schema() + + @property + def pydantic_type_adapter(self) -> pydantic.TypeAdapter[T]: + return self._ta def _build_error(self, exc: Exception, data: Union[str, bytes]) -> ValidationError: if isinstance(exc, UnicodeDecodeError): @@ -58,7 +64,7 @@ def _build_error(self, exc: Exception, data: Union[str, bytes]) -> ValidationErr "loc": ("__root__",), "input": data, } - return ValidationError.from_exception_data(self.core_schema["type"], [details]) + return ValidationError.from_exception_data(self._ta.core_schema["type"], [details]) def validate_simdjson( self, @@ -72,4 +78,4 @@ def validate_simdjson( obj = loads(data, schema=self._simdjson_schema, parser=parser) except (ValueError, TypeError, UnicodeDecodeError) as e: raise self._build_error(e, data) - return self.validate_python(obj, strict=strict, context=context) + return self._ta.validate_python(obj, strict=strict, context=context) diff --git a/tox.ini b/tox.ini index 94f5e35..fb355d2 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ isolated_build = True envlist = py{38}-pydantic{1,2}-pysimdjson{2,3,4,5,6},\ py{39,310}-pydantic{1,2}-pysimdjson{3,4,5,6},\ py{311}-pydantic{1,2}-pysimdjson{3,5,6},\ - py{312}-pydantic{1,2}-pysimdjson{6} + py{312}-pydantic{1,2}-pysimdjson{3,6} toxworkdir = {env:TOXDIR:.tox} labels = @@ -11,7 +11,7 @@ labels = py39 = py39-pydantic{1,2}-pysimdjson{3,4,5,6} py310 = py310-pydantic{1,2}-pysimdjson{3,4,5,6} py311 = py311-pydantic{1,2}-pysimdjson{3,5,6} - py312 = py312-pydantic{1,2}-pysimdjson{3,5,6} + py312 = py312-pydantic{1,2}-pysimdjson{3,6} [testenv] passenv= @@ -34,7 +34,7 @@ commands = pytest tests [testenv:mypy-pydantic{1,2}] labels = mypy -basepython = python3.8 +basepython = python3.12 deps = mypy pydantic1: pydantic~=1.0 From cc401bd0be4c23ecefbe612395072b2d8e84c1b8 Mon Sep 17 00:00:00 2001 From: Nikitin Artyom Date: Sun, 24 Mar 2024 20:58:12 +0300 Subject: [PATCH 4/8] Update lint.yml --- .github/workflows/lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c8115d0..48e6e1e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -27,10 +27,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup python3.12 + - name: Setup python3.8 uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: '3.8' - run: python -m pip install poetry==1.6 - run: poetry install - run: poetry run tox -m mypy From f2069a2bf5c6c60f940b4dbfe88b093f8384a5dd Mon Sep 17 00:00:00 2001 From: Nikitin Artyom Date: Sun, 24 Mar 2024 20:58:56 +0300 Subject: [PATCH 5/8] Update tox.ini --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index fb355d2..ed8108d 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,7 @@ labels = py39 = py39-pydantic{1,2}-pysimdjson{3,4,5,6} py310 = py310-pydantic{1,2}-pysimdjson{3,4,5,6} py311 = py311-pydantic{1,2}-pysimdjson{3,5,6} - py312 = py312-pydantic{1,2}-pysimdjson{3,6} + py312 = py312-pydantic{1,2}-pysimdjson{6} [testenv] passenv= @@ -34,7 +34,7 @@ commands = pytest tests [testenv:mypy-pydantic{1,2}] labels = mypy -basepython = python3.12 +basepython = python3.8 deps = mypy pydantic1: pydantic~=1.0 From 7059f5550b6572c292ba3672bef33bf827c8d129 Mon Sep 17 00:00:00 2001 From: Pavel Mosein Date: Sun, 24 Mar 2024 23:04:00 +0500 Subject: [PATCH 6/8] Fix linter --- Makefile | 4 ++-- simdjson_schemaful/pydantic/v2.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 2c8d456..50c10cf 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -PROJECT_NAME := simdjson_schemaful -PROJECT_PATH := $(PROJECT_PATH) +PROJECT_NAME ?= simdjson_schemaful +PROJECT_PATH := $(PROJECT_NAME) PYTHON_IMAGE := docker.io/snakepacker/python:all all: diff --git a/simdjson_schemaful/pydantic/v2.py b/simdjson_schemaful/pydantic/v2.py index cee2481..3d19747 100644 --- a/simdjson_schemaful/pydantic/v2.py +++ b/simdjson_schemaful/pydantic/v2.py @@ -1,5 +1,5 @@ import json -from typing import Any, Dict, Generic, Optional, TYPE_CHECKING, Type, TypeVar, Union +from typing import TYPE_CHECKING, Any, Dict, Generic, Optional, Type, TypeVar, Union import pydantic from pydantic import ValidationError @@ -64,7 +64,10 @@ def _build_error(self, exc: Exception, data: Union[str, bytes]) -> ValidationErr "loc": ("__root__",), "input": data, } - return ValidationError.from_exception_data(self._ta.core_schema["type"], [details]) + return ValidationError.from_exception_data( + self._ta.core_schema["type"], + [details], + ) def validate_simdjson( self, From c6d781446f8bc396587ec8d35b1cc54e4afeaa6b Mon Sep 17 00:00:00 2001 From: Nikitin Artyom Date: Sun, 24 Mar 2024 21:05:38 +0300 Subject: [PATCH 7/8] Update tox.ini --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index ed8108d..c9f5aed 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ isolated_build = True envlist = py{38}-pydantic{1,2}-pysimdjson{2,3,4,5,6},\ py{39,310}-pydantic{1,2}-pysimdjson{3,4,5,6},\ py{311}-pydantic{1,2}-pysimdjson{3,5,6},\ - py{312}-pydantic{1,2}-pysimdjson{3,6} + py{312}-pydantic{1,2}-pysimdjson{6} toxworkdir = {env:TOXDIR:.tox} labels = From db46fd0386b12e467bdae797942b6d4a22cdf27f Mon Sep 17 00:00:00 2001 From: Nikitin Artyom Date: Sun, 24 Mar 2024 21:09:54 +0300 Subject: [PATCH 8/8] Update Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 50c10cf..0d1c41e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PROJECT_NAME ?= simdjson_schemaful +PROJECT_NAME := simdjson_schemaful PROJECT_PATH := $(PROJECT_NAME) PYTHON_IMAGE := docker.io/snakepacker/python:all