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

fix: fix pydantic 2.10 #267

Merged
merged 10 commits into from
Nov 21, 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
36 changes: 0 additions & 36 deletions .github/workflows/test_dependents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,42 +58,6 @@ jobs:
aicsimageio/tests/readers/extra_readers/test_bioformats_reader.py \
aicsimageio/tests/readers/extra_readers/test_ome_zarr_reader.py

test-paquo:
name: test paquo
runs-on: ubuntu-latest
env:
QUPATH_VERSION: 0.4.3
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install .[test]
python -m pip install paquo

- name: Restore qupath cache
uses: actions/cache@v4
env:
CACHE_NUMBER: 0
with:
path: ./qupath/download
key: ${{ runner.os }}-qupath-v${{ env.CACHE_NUMBER }}

- name: Install qupath and set PAQUO_QUPATH_DIR
shell: bash
run: |
python -c "import os; os.makedirs('qupath/download', exist_ok=True)"
python -c "import os; os.makedirs('qupath/apps', exist_ok=True)"
python -m paquo get_qupath --install-path ./qupath/apps --download-path ./qupath/download ${{ env.QUPATH_VERSION }} \
| grep -v "^#" | sed "s/^/PAQUO_QUPATH_DIR=/" >> $GITHUB_ENV

- name: Test with pytest
run: pytest tests/test_paquo.py

test-nd2:
name: test nd2
runs-on: ubuntu-latest
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ classifiers = [
"Programming Language :: Python :: 3.12",
]
dynamic = ["version"]
dependencies = ["pydantic >=1.10.0", "pydantic-compat >=0.1.0", "xsdata >=23.6,<24.4"]
dependencies = [
"pydantic >=1.10.16, !=2.0, !=2.1, !=2.2, !=2.3",
"pydantic-compat >=0.1.0",
"xsdata >=23.6,<24.4",
]

[project.urls]
Source = "https://github.com/tlambert03/ome-types"
Expand Down Expand Up @@ -57,6 +61,7 @@ test = [
"xmlschema <2.5", # FIXME: determine why
"xsdata[cli]",
"types-lxml; python_version >= '3.8'",
"pdbpp; sys_platform != 'win32'", # for debugging
]
test-qt = ["qtpy", "pytest-qt"]
# pin ruff for builds because it changes often
Expand Down
3 changes: 2 additions & 1 deletion src/ome_autogen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def _fix_formatting(package_dir: str, ruff_ignore: list[str] = RUFF_IGNORE) -> N
def _check_mypy(package_dir: str) -> None:
_print_gray("Running mypy ...")

mypy = ["mypy", package_dir, "--strict"]
# FIXME: the call-overload disable is due to Field() in pydantic/pydantic-compat.
mypy = ["mypy", package_dir, "--strict", "--disable-error-code", "call-overload"]
try:
subprocess.check_output(mypy, stderr=subprocess.STDOUT) # noqa S
except subprocess.CalledProcessError as e: # pragma: no cover
Expand Down
11 changes: 8 additions & 3 deletions src/ome_types/_pydantic_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
if TYPE_CHECKING:
from pydantic.fields import FieldInfo

pydantic_version: tuple[int, ...] = tuple(
int(x) for x in pydantic.version.VERSION.split(".")[:2]
)

if pydantic.version.VERSION.startswith("2"):

if pydantic_version >= (2,):
try:
from pydantic_extra_types.color import Color as Color
except ImportError:
Expand All @@ -30,9 +34,10 @@ def field_regex(obj: type[BaseModel], field_name: str) -> str | None:
return meta.get("pattern") # type: ignore
return None

def get_default(f: FieldInfo) -> Any:
return f.get_default(call_default_factory=True, validated_data={})
kw: dict = {"validated_data": {}} if pydantic_version >= (2, 10) else {}

def get_default(f: FieldInfo) -> Any:
return f.get_default(call_default_factory=True, **kw)
else:
from pydantic.color import Color as Color # type: ignore [no-redef]

Expand Down
Loading