Coverage for src / bioimageio / spec / utils.py: 100%
25 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-08 13:52 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-08 13:52 +0000
1"""Utility functions for bioimage.io specifications (mostly IO)."""
3import json
4from typing import Any, Dict, List, TypedDict
6from ._description import ensure_description_is_dataset, ensure_description_is_model
7from ._internal.io import (
8 download,
9 extract_file_name,
10 get_reader,
11 get_sha256,
12 identify_bioimageio_yaml_file_name,
13 is_valid_bioimageio_yaml_name,
14)
15from ._internal.io_utils import (
16 load_array,
17 open_bioimageio_yaml,
18 read_yaml,
19 save_array,
20 write_yaml,
21)
22from ._internal.utils import files
24__all__ = [
25 "download",
26 "ensure_description_is_dataset",
27 "ensure_description_is_model",
28 "extract_file_name",
29 "get_file_name",
30 "get_reader",
31 "get_sha256",
32 "get_spdx_licenses",
33 "identify_bioimageio_yaml_file_name",
34 "is_valid_bioimageio_yaml_name",
35 "load_array",
36 "open_bioimageio_yaml",
37 "read_yaml",
38 "save_array",
39 "SpdxLicenseEntry",
40 "SpdxLicenses",
41 "write_yaml",
42]
44get_file_name = extract_file_name
47class SpdxLicenseEntry(TypedDict):
48 isDeprecatedLicenseId: bool
49 isKnownByZenodo: bool
50 isOsiApproved: bool
51 licenseId: str
52 name: str
53 reference: str
56class SpdxLicenses(TypedDict):
57 licenseListVersion: str
58 licenses: List[SpdxLicenseEntry]
59 releaseDate: str
62def get_spdx_licenses() -> SpdxLicenses:
63 """get details of the SPDX licenses known to bioimageio.spec"""
64 with (
65 files("bioimageio.spec")
66 .joinpath("static/spdx_licenses.json")
67 .open("r", encoding="utf-8")
68 ) as f:
69 return json.load(f)
72def get_bioimageio_json_schema() -> Dict[str, Any]:
73 """get the bioimageio specification as a JSON schema"""
74 with (
75 files("bioimageio.spec")
76 .joinpath("static/bioimageio_schema.json")
77 .open("r", encoding="utf-8")
78 ) as f:
79 return json.load(f)