Coverage for src/bioimageio/spec/utils.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-07 08:37 +0000

1import json 

2from typing import Any, Dict, List, TypedDict 

3 

4from ._description import ensure_description_is_dataset, ensure_description_is_model 

5from ._internal.io import ( 

6 download, 

7 extract_file_name, 

8 get_reader, 

9 get_sha256, 

10 identify_bioimageio_yaml_file_name, 

11 is_valid_bioimageio_yaml_name, 

12) 

13from ._internal.io_utils import ( 

14 load_array, 

15 open_bioimageio_yaml, 

16 read_yaml, 

17 save_array, 

18 write_yaml, 

19) 

20from ._internal.utils import files 

21 

22__all__ = [ 

23 "download", 

24 "ensure_description_is_dataset", 

25 "ensure_description_is_model", 

26 "extract_file_name", 

27 "get_file_name", 

28 "get_reader", 

29 "get_sha256", 

30 "get_spdx_licenses", 

31 "identify_bioimageio_yaml_file_name", 

32 "is_valid_bioimageio_yaml_name", 

33 "load_array", 

34 "open_bioimageio_yaml", 

35 "read_yaml", 

36 "save_array", 

37 "SpdxLicenseEntry", 

38 "SpdxLicenses", 

39 "write_yaml", 

40] 

41 

42get_file_name = extract_file_name 

43 

44 

45class SpdxLicenseEntry(TypedDict): 

46 isDeprecatedLicenseId: bool 

47 isKnownByZenodo: bool 

48 isOsiApproved: bool 

49 licenseId: str 

50 name: str 

51 reference: str 

52 

53 

54class SpdxLicenses(TypedDict): 

55 licenseListVersion: str 

56 licenses: List[SpdxLicenseEntry] 

57 releaseDate: str 

58 

59 

60def get_spdx_licenses() -> SpdxLicenses: 

61 """get details of the SPDX licenses known to bioimageio.spec""" 

62 with ( 

63 files("bioimageio.spec") 

64 .joinpath("static/spdx_licenses.json") 

65 .open("r", encoding="utf-8") 

66 ) as f: 

67 return json.load(f) 

68 

69 

70def get_bioimageio_json_schema() -> Dict[str, Any]: 

71 """get the bioimageio specification as a JSON schema""" 

72 with ( 

73 files("bioimageio.spec") 

74 .joinpath("static/bioimageio_schema.json") 

75 .open("r", encoding="utf-8") 

76 ) as f: 

77 return json.load(f)