-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8eba2c7
commit f2f53db
Showing
8 changed files
with
365 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
name: test dependents | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
pull_request: | ||
branches: | ||
- "main" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test-aicsimageio: | ||
name: test aicsimageio | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
repository: AllenCellModeling/aicsimageio | ||
submodules: true | ||
- uses: actions/checkout@v3 | ||
with: | ||
path: ome-types | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: Install aicsimageio | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install .[test] | ||
python -m pip install bioformats_jar | ||
- uses: actions/cache@v3 | ||
id: cache | ||
with: | ||
path: aicsimageio/tests/resources | ||
key: ${{ hashFiles('scripts/TEST_RESOURCES_HASH.txt') }} | ||
|
||
- name: Download Test Resources | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: python scripts/download_test_resources.py --debug | ||
|
||
- name: Install ome-types | ||
run: pip install . | ||
working-directory: ome-types | ||
|
||
- name: Run Tests | ||
run: | | ||
pytest --color=yes -k "not REMOTE" --ignore test_known_errors_without_cleaning \ | ||
aicsimageio/tests/readers/test_ome_tiff_reader.py \ | ||
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 | ||
# steps: | ||
# - uses: actions/checkout@v3 | ||
# with: | ||
# repository: bayer-science-for-a-better-life/paquo | ||
# fetch-depth: 0 | ||
# - uses: actions/checkout@v3 | ||
# with: | ||
# path: ome-types | ||
# fetch-depth: 0 | ||
|
||
# - name: Set up Python | ||
# uses: actions/setup-python@v4 | ||
# with: | ||
# python-version: "3.11" | ||
|
||
# - name: Install aicsimageio | ||
# run: | | ||
# python -m pip install --upgrade pip | ||
# python -m pip install -e .[dev] | ||
|
||
# - name: Install ome-types | ||
# run: pip install . | ||
# working-directory: ome-types | ||
|
||
# - name: Restore qupath cache | ||
# uses: actions/cache@v3 | ||
# 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 paquo/tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,3 +112,4 @@ src/ome_types/_version.py | |
docs/source/_autosummary | ||
.benchmarks/ | ||
_build/ | ||
qupath/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
from contextlib import suppress | ||
from typing import Iterable, List, MutableSequence, Type, Union, overload | ||
|
||
from pydantic import Field, ValidationError, validator | ||
|
||
from ome_types._mixins._base_type import OMEType | ||
from ome_types.model.ome_2016_06.ellipse import Ellipse | ||
from ome_types.model.ome_2016_06.label import Label | ||
from ome_types.model.ome_2016_06.line import Line | ||
from ome_types.model.ome_2016_06.mask import Mask | ||
from ome_types.model.ome_2016_06.point import Point | ||
from ome_types.model.ome_2016_06.polygon import Polygon | ||
from ome_types.model.ome_2016_06.polyline import Polyline | ||
from ome_types.model.ome_2016_06.rectangle import Rectangle | ||
|
||
_ShapeCls = (Rectangle, Mask, Point, Ellipse, Line, Polyline, Polygon, Label) | ||
ShapeType = Union[Rectangle, Mask, Point, Ellipse, Line, Polyline, Polygon, Label] | ||
_KINDS: dict[str, Type[ShapeType]] = { | ||
"rectangle": Rectangle, | ||
"mask": Mask, | ||
"point": Point, | ||
"ellipse": Ellipse, | ||
"line": Line, | ||
"polyline": Polyline, | ||
"polygon": Polygon, | ||
"label": Label, | ||
} | ||
|
||
|
||
class ShapeUnion(OMEType, MutableSequence[ShapeType]): # type: ignore[misc] | ||
# NOTE: in reality, this is List[ShapeGroupType]... but | ||
# for some reason that messes up xsdata data binding | ||
__root__: List[object] = Field( | ||
default_factory=list, | ||
metadata={ | ||
"type": "Elements", | ||
"choices": ( | ||
{ | ||
"name": "Label", | ||
"type": Label, | ||
}, | ||
{ | ||
"name": "Polygon", | ||
"type": Polygon, | ||
}, | ||
{ | ||
"name": "Polyline", | ||
"type": Polyline, | ||
}, | ||
{ | ||
"name": "Line", | ||
"type": Line, | ||
}, | ||
{ | ||
"name": "Ellipse", | ||
"type": Ellipse, | ||
}, | ||
{ | ||
"name": "Point", | ||
"type": Point, | ||
}, | ||
{ | ||
"name": "Mask", | ||
"type": Mask, | ||
}, | ||
{ | ||
"name": "Rectangle", | ||
"type": Rectangle, | ||
}, | ||
), | ||
}, | ||
) | ||
|
||
@validator("__root__", each_item=True) | ||
def _validate_shapes(cls, v: ShapeType) -> ShapeType: | ||
if isinstance(v, _ShapeCls): | ||
return v | ||
if isinstance(v, dict): | ||
# NOTE: this is here to preserve the v1 behavior of passing a dict like | ||
# {"kind": "label", "x": 0, "y": 0} | ||
# to create a label rather than a point | ||
if "kind" in v: | ||
kind = v.pop("kind").lower() | ||
return _KINDS[kind](**v) | ||
|
||
for cls_ in _ShapeCls: | ||
with suppress(ValidationError): | ||
return cls_(**v) | ||
raise ValueError(f"Invalid shape: {v}") | ||
|
||
def __repr__(self) -> str: | ||
return repr(self.__root__) | ||
|
||
def __delitem__(self, _idx: int | slice) -> None: | ||
del self.__root__[_idx] | ||
|
||
@overload | ||
def __getitem__(self, _idx: int) -> ShapeType: | ||
... | ||
|
||
@overload | ||
def __getitem__(self, _idx: slice) -> List[ShapeType]: | ||
... | ||
|
||
def __getitem__(self, _idx: int | slice) -> ShapeType | List[ShapeType]: | ||
return self.__root__[_idx] # type: ignore[return-value] | ||
|
||
def __len__(self) -> int: | ||
return super().__len__() | ||
|
||
@overload | ||
def __setitem__(self, _idx: int, _val: ShapeType) -> None: | ||
... | ||
|
||
@overload | ||
def __setitem__(self, _idx: slice, _val: Iterable[ShapeType]) -> None: | ||
... | ||
|
||
def __setitem__( | ||
self, _idx: int | slice, _val: ShapeType | Iterable[ShapeType] | ||
) -> None: | ||
self.__root__[_idx] = _val | ||
|
||
def insert(self, index: int, value: ShapeType) -> None: | ||
self.__root__.insert(index, value) | ||
|
||
# for some reason, without overloading this... append() adds things to the | ||
# beginning of the list instead of the end | ||
def append(self, value: ShapeType) -> None: | ||
self.__root__.append(value) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.