Skip to content

Commit ad6daf8

Browse files
authored
Merge pull request #259 from bioimage-io/update_for_resolved_paths
Update for resolved paths
2 parents 261ff92 + 02245ee commit ad6daf8

File tree

7 files changed

+57
-21
lines changed

7 files changed

+57
-21
lines changed

dev/environment-base.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ dependencies:
1515
- pytorch
1616
- onnxruntime
1717
- tensorflow >=1.12,<2.0
18-
- tifffile
18+
- tifffile <=2022.4.8 # pin fixes Syntax error; see https://github.com/bioimage-io/core-bioimage-io-python/pull/259
1919
- pip:
2020
- keras==1.2.2

dev/environment-tf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ dependencies:
1313
- python >=3.7,<3.8 # this environment is only available for python 3.7
1414
- xarray
1515
- tensorflow >1.14,<2.0
16-
- tifffile
16+
- tifffile <=2022.4.8 # pin fixes Syntax error; see https://github.com/bioimage-io/core-bioimage-io-python/pull/259
1717
- keras

dev/environment-torch.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ dependencies:
1414
- xarray
1515
- pytorch
1616
- onnxruntime
17-
- tifffile
17+
- tifffile <=2022.4.8 # pin fixes Syntax error; see https://github.com/bioimage-io/core-bioimage-io-python/pull/259
18+

setup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@
2525
"Programming Language :: Python :: 3.8",
2626
],
2727
packages=find_namespace_packages(exclude=["tests"]), # Required
28-
install_requires=["bioimageio.spec>=0.4.5", "imageio>=2.5", "numpy", "ruamel.yaml", "tqdm", "xarray"],
28+
install_requires=[
29+
"bioimageio.spec>=0.4.5",
30+
"imageio>=2.5",
31+
"numpy",
32+
"ruamel.yaml",
33+
"tqdm",
34+
"xarray",
35+
"tifffile<=2022.4.8", # fixes Syntax error; see https://github.com/bioimage-io/core-bioimage-io-python/pull/259
36+
],
2937
include_package_data=True,
3038
extras_require={
3139
"test": ["pytest", "black", "mypy"],

tests/build_spec/test_build_spec.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import os
1+
from marshmallow import missing
2+
23
import bioimageio.spec as spec
34
from bioimageio.core import load_raw_resource_description, load_resource_description
45
from bioimageio.core.resource_io import nodes
56
from bioimageio.core.resource_io.utils import resolve_source
67
from bioimageio.core.resource_tests import test_model as _test_model
7-
from marshmallow import missing
88

99

1010
def _test_build_spec(
@@ -16,7 +16,6 @@ def _test_build_spec(
1616
use_implicit_output_shape=False,
1717
add_deepimagej_config=False,
1818
use_original_covers=False,
19-
use_absoloute_arch_path=False,
2019
training_data=None,
2120
parent=None,
2221
):
@@ -44,11 +43,6 @@ def _test_build_spec(
4443
if weight_type == "pytorch_state_dict":
4544
model_kwargs = None if weight_spec.kwargs is missing else weight_spec.kwargs
4645
architecture = str(weight_spec.architecture)
47-
if use_absoloute_arch_path:
48-
arch_path, cls_name = architecture.split(":")
49-
arch_path = os.path.abspath(os.path.join(root, arch_path))
50-
assert os.path.exists(arch_path)
51-
architecture = f"{arch_path}:{cls_name}"
5246
weight_type_ = None # the weight type can be auto-detected
5347
elif weight_type == "torchscript":
5448
architecture = None
@@ -233,10 +227,3 @@ def test_build_spec_deepimagej_keras(unet2d_keras, tmp_path):
233227
# test with original covers
234228
def test_build_spec_with_original_covers(unet2d_nuclei_broad_model, tmp_path):
235229
_test_build_spec(unet2d_nuclei_broad_model, tmp_path / "model.zip", "torchscript", use_original_covers=True)
236-
237-
238-
# test with absolute path for the architecture file
239-
def test_build_spec_abs_arch_path(unet2d_nuclei_broad_model, tmp_path):
240-
_test_build_spec(
241-
unet2d_nuclei_broad_model, tmp_path / "model.zip", "pytorch_state_dict", use_absoloute_arch_path=True
242-
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import dataclasses
2+
3+
import pytest
4+
5+
from bioimageio.core.prediction_pipeline._processing import KNOWN_PROCESSING
6+
from bioimageio.core.prediction_pipeline._utils import FIXED
7+
8+
try:
9+
from typing import get_args
10+
except ImportError:
11+
from typing_extensions import get_args # type: ignore
12+
13+
14+
@pytest.mark.parametrize(
15+
"proc",
16+
list(KNOWN_PROCESSING["pre"].values()) + list(KNOWN_PROCESSING["post"].values()),
17+
)
18+
def test_no_req_measures_for_mode_fixed(proc):
19+
# check if mode=fixed is valid for this proc
20+
for f in dataclasses.fields(proc):
21+
if f.name == "mode":
22+
break
23+
else:
24+
raise AttributeError("Processing is missing mode attribute")
25+
# mode is always annotated as literals (or literals of literals)
26+
valid_modes = get_args(f.type)
27+
for inner in get_args(f.type):
28+
valid_modes += get_args(inner)
29+
30+
if FIXED not in valid_modes:
31+
return
32+
33+
# we might be missing required kwargs. These have marshmallow.missing value as default
34+
# and raise a TypeError is in __post_init__()
35+
proc.__post_init__ = lambda self: None # ignore missing kwargs
36+
37+
proc_instance = proc(tensor_name="tensor_name", mode=FIXED)
38+
req_measures = proc_instance.get_required_measures()
39+
assert not req_measures

tests/test_export_package.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_package_with_folder(unet2d_nuclei_broad_model):
3737
# alter package to have its documentation in a nested folder
3838
doc = model.documentation
3939
assert doc is not missing
40+
doc = doc.relative_to(model.root_path)
4041
assert not doc.is_absolute()
4142
new_doc = Path("nested") / "folder" / doc
4243
(package_folder / new_doc).parent.mkdir(parents=True)
@@ -55,5 +56,5 @@ def test_package_with_folder(unet2d_nuclei_broad_model):
5556
# load altered package
5657
reloaded_model = load_raw_resource_description(altered_package_folder / "rdf.yaml")
5758
assert isinstance(reloaded_model, raw_nodes.Model)
58-
assert reloaded_model.documentation == new_doc
59-
assert (altered_package_folder / reloaded_model.documentation).exists()
59+
assert reloaded_model.documentation.as_posix().endswith(new_doc.as_posix())
60+
assert reloaded_model.documentation.exists()

0 commit comments

Comments
 (0)