Coverage for bioimageio/spec/_internal/constants.py: 100%
27 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-02 14:21 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-02 14:21 +0000
1from __future__ import annotations
3import json
4from types import MappingProxyType
5from typing import Mapping, NamedTuple, Sequence, Set, Union
7from .utils import files
9with files("bioimageio.spec").joinpath("VERSION").open("r", encoding="utf-8") as f:
10 VERSION: str = json.load(f)["version"]
11 assert isinstance(VERSION, str), VERSION
14DOI_REGEX = ( # lax DOI regex validating the first 7 DOI characters only
15 r"^10\.[0-9]{4}.+$"
16)
18SHA256_HINT = """You can drag and drop your file to this
19[online tool](http://emn178.github.io/online-tools/sha256_checksum.html) to generate a SHA256 in your browser.
20Or you can generate a SHA256 checksum with Python's `hashlib`,
21[here is a codesnippet](https://gist.github.com/FynnBe/e64460463df89439cff218bbf59c1100)."""
23with files("bioimageio.spec").joinpath("static/tag_categories.json").open(
24 "r", encoding="utf-8"
25) as f:
26 TAG_CATEGORIES: Mapping[str, Mapping[str, Sequence[str]]] = json.load(f)
28# SI unit regex adapted from https://stackoverflow.com/a/3573731
29_prefix = "(Q|R|Y|Z|E|P|T|G|M|k|h|da|d|c|m|µ|n|p|f|a|z|y|r|q)"
30_unit = "(m|g|s|A|K|mol|cd|Hz|N|Pa|J|W|C|V|F|Ω|S|Wb|T|H|lm|lx|Bq|Gy|Sv|kat|l|L)"
31_any_power = r"(\^[+-]?[1-9]\d*)"
32_pos_power = r"(\^+?[1-9]\d*)"
33_unit_ap = f"{_prefix}?{_unit}{_any_power}?"
34_unit_pp = f"{_prefix}?{_unit}{_pos_power}?"
35SI_UNIT_REGEX = f"^{_unit_ap}((·{_unit_ap})|(/{_unit_pp}))*$"
38class _DtypeLimit(NamedTuple):
39 min: Union[int, float]
40 max: Union[int, float]
43# numpy.dtype limits; see scripts/generate_dtype_limits.py
44DTYPE_LIMITS = MappingProxyType(
45 {
46 "float32": _DtypeLimit(-3.4028235e38, 3.4028235e38),
47 "float64": _DtypeLimit(-1.7976931348623157e308, 1.7976931348623157e308),
48 "uint8": _DtypeLimit(0, 255),
49 "int8": _DtypeLimit(-128, 127),
50 "uint16": _DtypeLimit(0, 65535),
51 "int16": _DtypeLimit(-32768, 32767),
52 "uint32": _DtypeLimit(0, 4294967295),
53 "int32": _DtypeLimit(-2147483648, 2147483647),
54 "uint64": _DtypeLimit(0, 18446744073709551615),
55 "int64": _DtypeLimit(-9223372036854775808, 9223372036854775807),
56 }
57)
59# TODO: cache/store known gh users in file
60KNOWN_GH_USERS: Set[str] = {
61 "clementcaporal",
62 "donglaiw",
63 "jansanrom",
64 "pedgomgal1",
65 "aaitorg",
66 "bioimageiobot",
67 "carlosuc3m",
68 "cfusterbarcelo",
69 "constantinpape",
70 "ctr26",
71 "danifranco",
72 "esgomezm",
73 "fynnbe",
74 "githubuser2",
75 "iarganda",
76 "ivanhcenalmor",
77 "jansanrom",
78 "k-dominik",
79 "lenkaback",
80 "oeway",
81}
82N_KNOWN_GH_USERS = len(KNOWN_GH_USERS)
83KNOWN_INVALID_GH_USERS: Set[str] = {"arratemunoz", "lmescu"}
84N_KNOWN_INVALID_GH_USERS = len(KNOWN_INVALID_GH_USERS)