Skip to content

Commit

Permalink
Merge branch 'main' into py313
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Nov 21, 2024
2 parents d0fa0c2 + e4bda9e commit 6514ce4
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 64 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
pip uninstall -y lxml xmlschema
pytest --cov --cov-report=xml --cov-append
- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}

Expand All @@ -75,7 +75,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.11", "3.13"]
python-version: ["3.9", "3.10", "3.12"]

test-widget:
name: test-widget
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
python -m pip install 'pydantic>=2'
pytest --cov --cov-report=xml --cov-append
- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}

Expand All @@ -153,7 +153,7 @@ jobs:
run: pytest --cov --cov-report=xml --cov-append -k test_autogen
env:
TEST_AUTOGEN: "1"
- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}

Expand Down
38 changes: 1 addition & 37 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 Expand Up @@ -144,7 +108,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install -U pip
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ ci:

repos:
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.19
rev: v0.23
hooks:
- id: validate-pyproject

- repo: https://github.com/crate-ci/typos
rev: v1.24.5
rev: typos-dict-v0.11.35
hooks:
- id: typos
args: [--force-exclude] # omit --write-changes

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
rev: v0.7.4
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.13.0
hooks:
- id: mypy
exclude: ^tests|^docs|_napari_plugin|widgets
additional_dependencies:
- pydantic>=2
- pydantic>=2.10
- pydantic-compat
- xsdata==24.2.1
- Pint
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [v0.5.3](https://github.com/tlambert03/ome-types/tree/v0.5.3) (2024-11-21)

[Full Changelog](https://github.com/tlambert03/ome-types/compare/v0.5.2...v0.5.3)

**Fixed bugs:**

- fix: fix pydantic 2.10 [\#267](https://github.com/tlambert03/ome-types/pull/267) ([tlambert03](https://github.com/tlambert03))

**Merged pull requests:**

- ci\(dependabot\): bump codecov/codecov-action from 4 to 5 [\#264](https://github.com/tlambert03/ome-types/pull/264) ([dependabot[bot]](https://github.com/apps/dependabot))
- ci\(pre-commit.ci\): autoupdate [\#263](https://github.com/tlambert03/ome-types/pull/263) ([pre-commit-ci[bot]](https://github.com/apps/pre-commit-ci))

## [v0.5.2](https://github.com/tlambert03/ome-types/tree/v0.5.2) (2024-09-23)

[Full Changelog](https://github.com/tlambert03/ome-types/compare/v0.5.1.post1...v0.5.2)
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.13",
]
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",
"pdbpp; sys_platform != 'win32'", # for debugging
]
test-qt = ["qtpy", "pytest-qt"]
# pin ruff for builds because it changes often
Expand Down
7 changes: 5 additions & 2 deletions 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 Expand Up @@ -221,7 +222,9 @@ def _disp_type(obj: Any) -> str:
else:
_fields = [
f"{k}: {_disp_type(v.annotation)}"
for k, v in sorted(m.model_fields.items())
# this type ignore indicates something that may break in pydantic 3
# but for now, it's confusing and I think it's an error
for k, v in sorted(m.model_fields.items()) # type: ignore
]
if _fields:
module += CLASS.format(
Expand Down
9 changes: 5 additions & 4 deletions src/ome_types/_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import operator
import os
import warnings
from contextlib import AbstractContextManager, nullcontext, suppress
from contextlib import nullcontext, suppress
from functools import cache
from pathlib import Path
from struct import Struct
Expand All @@ -27,6 +27,7 @@

if TYPE_CHECKING:
from collections.abc import Iterable
from contextlib import AbstractContextManager
from typing import Any, BinaryIO, Literal, TypedDict
from xml.etree import ElementTree

Expand Down Expand Up @@ -175,7 +176,7 @@ def _unpack(fh: BinaryIO, strct: Struct) -> int:
def tiff2xml(path: Path | str | BinaryIO) -> bytes:
"""Extract the OME-XML from a TIFF file."""
if hasattr(path, "read"):
ctx: AbstractContextManager = nullcontext(path)
ctx: AbstractContextManager[BinaryIO] = nullcontext(path) # type: ignore[arg-type]
else:
ctx = Path(path).open(mode="rb")

Expand Down Expand Up @@ -562,7 +563,7 @@ def _get_ns_elem(elem: ET._Element | AnyElementTree) -> str:
"""Get namespace from an element or element tree."""
root = elem.getroot() if hasattr(elem, "getroot") else elem
# return root.nsmap[root.prefix] this only works for lxml
return root.tag.split("}", 1)[0].lstrip("{")
return str(root.tag).split("}", 1)[0].lstrip("{")


def _get_ns_file(source: FileLike) -> str:
Expand All @@ -583,7 +584,7 @@ def _get_root_ome_type(xml: FileLike | AnyElementTree) -> type[OMEType]:
if hasattr(xml, "seek"):
xml.seek(0)
_, root = next(ET.iterparse(xml, events=("start",)))
localname = cast("ET._Element", root).tag.rsplit("}", 1)[-1]
localname = str(root.tag).rsplit("}", 1)[-1]

if hasattr(xml, "seek"):
xml.seek(0)
Expand Down
14 changes: 10 additions & 4 deletions src/ome_types/_pydantic_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,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 @@ -20,7 +24,8 @@ def field_type(field: FieldInfo) -> Any:
return field.annotation

def field_regex(obj: type[BaseModel], field_name: str) -> str | None:
field_info = obj.model_fields[field_name]
# typing is incorrect at the moment, but may indicate breakage in pydantic 3
field_info = obj.model_fields[field_name] # type: ignore [index]
meta = field_info.json_schema_extra or {}
# if a "metadata" key exists... use it.
# After pydantic-compat 0.2, this is where it will be.
Expand All @@ -30,9 +35,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)
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
4 changes: 2 additions & 2 deletions src/xsdata_pydantic_basemodel/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class AnyElement(PydanticCompatMixin, BaseModel):
tail: Optional[str] = Field(default=None)
children: list["AnyElement"] = Field(
default_factory=list,
metadata={"type": XmlType.WILDCARD}, # type: ignore [call-arg]
metadata={"type": XmlType.WILDCARD}, # type: ignore [call-arg,call-overload]
)
attributes: dict[str, str] = Field(
default_factory=dict,
metadata={"type": XmlType.ATTRIBUTES}, # type: ignore [call-arg]
metadata={"type": XmlType.ATTRIBUTES}, # type: ignore [call-arg,call-overload]
)

model_config: ClassVar["ConfigDict"] = {"arbitrary_types_allowed": True}
Expand Down
2 changes: 1 addition & 1 deletion src/xsdata_pydantic_basemodel/pydantic_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ def dataclass_fields(obj: type[M]) -> tuple[dc.Field, ...]:
"""Return a tuple of dataclass fields for the given pydantic model class."""
return tuple(
_pydantic_field_to_dataclass_field(name, f)
for name, f in obj.model_fields.items()
for name, f in obj.model_fields.items() # type: ignore
)
8 changes: 4 additions & 4 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import contextlib
from contextlib import nullcontext
from contextlib import AbstractContextManager, nullcontext
from typing import TYPE_CHECKING, Callable

import pytest
Expand Down Expand Up @@ -29,10 +29,10 @@
@pytest.mark.filterwarnings("ignore:unclosed file")
@pytest.mark.parametrize("backend", VALIDATORS)
def test_validation_good(valid_xml: Path, backend: str) -> None:
if valid_xml.name not in REQUIRES_TRANSFORM:
ctx = nullcontext()
if valid_xml.name in REQUIRES_TRANSFORM:
ctx: AbstractContextManager = pytest.warns(match="Transformed source from")
else:
ctx = pytest.warns(match="Transformed source from")
ctx = nullcontext()
with ctx:
VALIDATORS[backend](valid_xml)

Expand Down

0 comments on commit 6514ce4

Please sign in to comment.