Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python3.12 #11

Merged
merged 10 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
steps:
- uses: actions/checkout@v4
- name: Setup python${{ matrix.python }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROJECT_NAME := simdjson_schemaful
PROJECT_PATH := $(PROJECT_PATH)
PROJECT_PATH := $(PROJECT_NAME)
PYTHON_IMAGE := docker.io/snakepacker/python:all

all:
Expand Down
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 }

Expand Down
21 changes: 15 additions & 6 deletions simdjson_schemaful/pydantic/v2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import TYPE_CHECKING, Any, Dict, Optional, Type, TypeVar, Union
from typing import TYPE_CHECKING, Any, Dict, Generic, Optional, Type, TypeVar, Union

import pydantic
from pydantic import ValidationError
Expand Down Expand Up @@ -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):
Expand All @@ -58,7 +64,10 @@ 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,
Expand All @@ -72,4 +81,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)
17 changes: 10 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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{6}

[testenv]
passenv=
Expand All @@ -26,6 +28,7 @@ deps =
pysimdjson3: pysimdjson~=3.0
pysimdjson4: pysimdjson~=4.0
pysimdjson5: pysimdjson~=5.0
pysimdjson6: pysimdjson~=6.0

commands = pytest tests

Expand Down
Loading