Skip to content

Commit bb61063

Browse files
authored
Merge pull request #466 from bioimage-io/dev
improve resource testing with subcommand
2 parents 24aee14 + f547ebc commit bb61063

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ may be controlled with the `LOGURU_LEVEL` environment variable.
371371
- improved handling of summary argument to not create a path with brackets when given a list of paths.
372372
- improved backward compatibility when runnig tests for models specifying an older bioimageio.core version in their environment.
373373
This is relevant when using `runtime_env="as-described"`.
374-
It works by simply trying option `--summary` (new option name) and `--summary-path` (outdated option name).
374+
It works by simply trying option `--summary` (new option name) and `--summary-path` (outdated option name)
375375

376376
### 0.9.0
377377

bioimageio/core/_resource_tests.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,9 @@ def test_description(
222222
environment YAML file based on the model weights description.
223223
- A `BioimageioCondaEnv` or a path to a conda environment YAML file.
224224
Note: The `bioimageio.core` dependency will be added automatically if not present.
225-
run_command: (Experimental feature!) Function to execute (conda) terminal commands in a subprocess
226-
(ignored if **runtime_env** is `"currently-active"`).
225+
run_command: (Experimental feature!) Function to execute (conda) terminal commands in a subprocess.
226+
The function should raise an exception if the command fails.
227+
**run_command** is ignored if **runtime_env** is `"currently-active"`.
227228
"""
228229
if runtime_env == "currently-active":
229230
rd = load_description_and_test(
@@ -371,8 +372,6 @@ def _test_in_env(
371372
except Exception as e:
372373
raise RuntimeError("Conda not available") from e
373374

374-
working_dir.mkdir(parents=True, exist_ok=True)
375-
summary_path = working_dir / "summary.json"
376375
try:
377376
run_command(["conda", "activate", env_name])
378377
except Exception:
@@ -404,28 +403,39 @@ def _test_in_env(
404403
)
405404
return summary
406405

406+
working_dir.mkdir(parents=True, exist_ok=True)
407+
summary_path = working_dir / "summary.json"
408+
assert not summary_path.exists(), "Summary file already exists"
407409
cmd = []
410+
cmd_error = None
408411
for summary_path_arg_name in ("summary", "summary-path"):
409-
run_command(
410-
cmd := (
411-
[
412-
"conda",
413-
"run",
414-
"-n",
415-
env_name,
416-
"bioimageio",
417-
"test",
418-
str(source),
419-
f"--{summary_path_arg_name}={summary_path.as_posix()}",
420-
f"--determinism={determinism}",
421-
]
422-
+ ([f"--expected-type={expected_type}"] if expected_type else [])
423-
+ (["--stop-early"] if stop_early else [])
412+
try:
413+
run_command(
414+
cmd := (
415+
[
416+
"conda",
417+
"run",
418+
"-n",
419+
env_name,
420+
"bioimageio",
421+
"test",
422+
str(source),
423+
f"--{summary_path_arg_name}={summary_path.as_posix()}",
424+
f"--determinism={determinism}",
425+
]
426+
+ ([f"--expected-type={expected_type}"] if expected_type else [])
427+
+ (["--stop-early"] if stop_early else [])
428+
)
424429
)
425-
)
430+
except Exception as e:
431+
cmd_error = f"Failed to run command '{' '.join(cmd)}': {e}."
432+
426433
if summary_path.exists():
427434
break
428435
else:
436+
if cmd_error is not None:
437+
logger.warning(cmd_error)
438+
429439
return ValidationSummary(
430440
name="calling bioimageio test command",
431441
source_name=str(source),
@@ -448,7 +458,7 @@ def _test_in_env(
448458
env=set(),
449459
)
450460

451-
return ValidationSummary.model_validate_json(summary_path.read_bytes())
461+
return ValidationSummary.load_json(summary_path)
452462

453463

454464
@overload

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"packaging>=17.0",
6969
"pdoc",
7070
"pre-commit",
71-
"pyright==1.1.402",
71+
"pyright==1.1.403",
7272
"segment-anything", # for model testing
7373
"timm", # for model testing
7474
# "crick", # currently requires python<=3.9

0 commit comments

Comments
 (0)