From ee04688e64433c9597b1fd152624dff55c95a918 Mon Sep 17 00:00:00 2001 From: crusaderky Date: Thu, 11 Dec 2025 17:37:56 +0000 Subject: [PATCH 1/2] WIP Pydantic v2 migration --- pyproject.toml | 2 ++ thinc/tests/test_config.py | 23 ++++------------------- thinc/tests/test_types.py | 7 +------ thinc/util.py | 2 -- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 243a60209..a379a45b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,4 +78,6 @@ filterwarnings = [ "ignore:Module thinc was previously imported, but not measured:coverage.exceptions.CoverageWarning", # https://github.com/coveragepy/coveragepy/issues/1790 "ignore:Plugin file tracers:coverage.exceptions.CoverageWarning", + # FIXME Pydantic V2 migration + "ignore::pydantic.warnings.PydanticDeprecatedSince20", ] diff --git a/thinc/tests/test_config.py b/thinc/tests/test_config.py index a3f4ede46..2302777ae 100644 --- a/thinc/tests/test_config.py +++ b/thinc/tests/test_config.py @@ -1,24 +1,9 @@ -import inspect -import pickle -from types import GeneratorType -from typing import Any, Callable, Dict, Iterable, List, Optional, Union - import catalogue import numpy -import pytest - -try: - from pydantic.v1 import BaseModel, PositiveInt, StrictBool, StrictFloat, constr -except ImportError: - from pydantic import BaseModel, PositiveInt, StrictBool, StrictFloat, constr # type: ignore +from pydantic import BaseModel, StrictBool import thinc.config -from thinc.api import Config, Model, NumpyOps, RAdam -from thinc.config import ConfigValidationError -from thinc.types import Generator, Ragged -from thinc.util import partial - -from .util import make_tempdir +from thinc.api import Config, Model, RAdam EXAMPLE_CONFIG = """ [optimizer] @@ -175,11 +160,11 @@ def test_objects_from_config(): } @thinc.registry.optimizers.register("my_cool_optimizer.v1") - def make_my_optimizer(learn_rate: List[float], beta1: float): + def make_my_optimizer(learn_rate: list[float], beta1: float): return RAdam(learn_rate, beta1=beta1) @thinc.registry.schedules("my_cool_repetitive_schedule.v1") - def decaying(base_rate: float, repeat: int) -> List[float]: + def decaying(base_rate: float, repeat: int) -> list[float]: return repeat * [base_rate] optimizer = my_registry.resolve(config)["optimizer"] diff --git a/thinc/tests/test_types.py b/thinc/tests/test_types.py index 1a3310d30..7a53e7aad 100644 --- a/thinc/tests/test_types.py +++ b/thinc/tests/test_types.py @@ -1,11 +1,6 @@ import numpy import pytest - -try: - from pydantic.v1 import ValidationError, create_model -except ImportError: - from pydantic import ValidationError, create_model # type: ignore - +from pydantic import ValidationError, create_model from thinc.types import ( Floats1d, diff --git a/thinc/util.py b/thinc/util.py index f32f10344..80887715d 100644 --- a/thinc/util.py +++ b/thinc/util.py @@ -23,8 +23,6 @@ ) import numpy -from packaging.version import Version -from pydantic import ConfigDict, ValidationError, create_model from wasabi import table # type: ignore from .compat import ( From 9567ca1b68c357d904b1a6f64fa38c63c08bc960 Mon Sep 17 00:00:00 2001 From: crusaderky Date: Thu, 11 Dec 2025 16:57:56 +0000 Subject: [PATCH 2/2] Test vs. nightly builds and git tip of key dependencies --- .github/workflows/tests.yml | 56 ++++++++++++++++++++++++++++++++- thinc/tests/model/test_model.py | 2 ++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c5430a54c..ba6b97107 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -51,7 +51,7 @@ jobs: python -m mypy thinc --no-implicit-reexport tests: - name: ${{ matrix.os }} - Python ${{ matrix.python_version }} + name: ${{ matrix.os }} - Python ${{ matrix.python_version }} ${{ matrix.nightly }} strategy: fail-fast: false matrix: @@ -63,6 +63,11 @@ jobs: - windows-latest - windows-11-arm python_version: ["3.10", "3.11", "3.12", "3.13"] + nightly: [""] # Use only official releases + include: + - os: ubuntu-latest + python_version: "3.13" + nightly: "nightly" # Use nightly wheels and git tips exclude: - os: windows-11-arm python_version: "3.10" @@ -83,9 +88,29 @@ jobs: - name: Install build dependencies run: python -m pip install --upgrade build pip wheel + - name: Install nightly build dependencies + if: matrix.nightly == 'nightly' + run: | + pip install --upgrade --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/ numpy blis + + # Install dependencies for --no-isolation + pip install setuptools \ + "cython>=3.0,<4.0" \ + "cymem>=2.0.2,<3" \ + "murmurhash>=1.0.2,<2" + + # TODO this won't be necessary long term after release 3.0.13 + # (replace with "preshed>=3.0.2,<3.1.0" above) + pip install git+https://github.com/explosion/preshed.git@v3.0.x + - name: Build sdist and wheel + if: matrix.nightly == '' run: python -m build + - name: Build sdist and wheel (no build isolation) + if: matrix.nightly == 'nightly' + run: python -m build --no-isolation + - name: Delete source directory run: rm -rf thinc shell: bash @@ -109,6 +134,35 @@ jobs: - name: Install notebook test requirements run: python -m ipykernel install --name thinc-notebook-tests --user + - name: Install nightly runtime dependencies + if: matrix.nightly == 'nightly' + run: | + pip install --upgrade --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/ numpy blis + + # TODO this won't be necessary long term after release 3.0.13 + pip install --upgrade git+https://github.com/explosion/preshed.git@v3.0.x + + # TODO this won't be necessary long term after a free-threading release + # TODO merge https://github.com/ultrajson/ultrajson/pull/689 + # pip install --upgrade git+https://github.com/ultrajson/ultrajson.git + pip install --upgrade git+https://github.com/crusaderky/ultrajson.git@free-threading + + # FIXME msgpack-python is not fully compatible with free-threading at the + # moment of writing; naive pip install from git tip fails: + # https://github.com/msgpack/msgpack-python/issues/613 + + # TODO this won't be necessary long term after release 1.0.0 + # FIXME confection git tip is broken + # pip install --upgrade git+https://github.com/explosion/confection.git + + # TODO this won't be necessary long term after release 0.2.1 + pip install --upgrade git+https://github.com/explosion/ml-datasets + + # TODO this won't be necessary long term after release 3.0 + # TODO merge https://github.com/explosion/srsly/pull/120 + # pip install --upgrade git+https://github.com/explosion/srsly.git + pip install --upgrade git+https://github.com/crusaderky/srsly.git@ft + - name: List installed packages run: python -m pip list diff --git a/thinc/tests/model/test_model.py b/thinc/tests/model/test_model.py index 2284e93b2..f7e4ca8f9 100644 --- a/thinc/tests/model/test_model.py +++ b/thinc/tests/model/test_model.py @@ -514,6 +514,8 @@ def dummy_model(name, layers): assert a.layers[1].get_ref("y") == y_debug +# NumPy >=2.4 issues a warning when unpacking mnist pickle +@pytest.mark.filterwarnings("ignore::numpy.exceptions.VisibleDeprecationWarning") @pytest.mark.xfail( platform.system() == "Darwin", reason="SSL: CERTIFICATE_VERIFY_FAILED",