Coverage for bioimageio/spec/_internal/constants.py: 100%
29 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-02-05 13:53 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-02-05 13:53 +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)
18IN_PACKAGE_MESSAGE = "∈📦 "
19"""DEPRECATED, use ImportantFileSource to indicate that a file source should be included in a package"""
22SHA256_HINT = """You can drag and drop your file to this
23[online tool](http://emn178.github.io/online-tools/sha256_checksum.html) to generate a SHA256 in your browser.
24Or you can generate a SHA256 checksum with Python's `hashlib`,
25[here is a codesnippet](https://gist.github.com/FynnBe/e64460463df89439cff218bbf59c1100)."""
27with files("bioimageio.spec").joinpath("static/tag_categories.json").open(
28 "r", encoding="utf-8"
29) as f:
30 TAG_CATEGORIES: Mapping[str, Mapping[str, Sequence[str]]] = json.load(f)
32# SI unit regex adapted from https://stackoverflow.com/a/3573731
33_prefix = "(Q|R|Y|Z|E|P|T|G|M|k|h|da|d|c|m|µ|n|p|f|a|z|y|r|q)"
34_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)"
35_any_power = r"(\^[+-]?[1-9]\d*)"
36_pos_power = r"(\^+?[1-9]\d*)"
37_unit_ap = f"{_prefix}?{_unit}{_any_power}?"
38_unit_pp = f"{_prefix}?{_unit}{_pos_power}?"
39SI_UNIT_REGEX = f"^{_unit_ap}((·{_unit_ap})|(/{_unit_pp}))*$"
42class _DtypeLimit(NamedTuple):
43 min: Union[int, float]
44 max: Union[int, float]
47# numpy.dtype limits; see scripts/generate_dtype_limits.py
48DTYPE_LIMITS = MappingProxyType(
49 {
50 "float32": _DtypeLimit(-3.4028235e38, 3.4028235e38),
51 "float64": _DtypeLimit(-1.7976931348623157e308, 1.7976931348623157e308),
52 "uint8": _DtypeLimit(0, 255),
53 "int8": _DtypeLimit(-128, 127),
54 "uint16": _DtypeLimit(0, 65535),
55 "int16": _DtypeLimit(-32768, 32767),
56 "uint32": _DtypeLimit(0, 4294967295),
57 "int32": _DtypeLimit(-2147483648, 2147483647),
58 "uint64": _DtypeLimit(0, 18446744073709551615),
59 "int64": _DtypeLimit(-9223372036854775808, 9223372036854775807),
60 }
61)
63# TODO: cache/store known gh users in file
64KNOWN_GH_USERS: Set[str] = {
65 "clementcaporal",
66 "donglaiw",
67 "jansanrom",
68 "pedgomgal1",
69 "aaitorg",
70 "bioimageiobot",
71 "carlosuc3m",
72 "cfusterbarcelo",
73 "constantinpape",
74 "ctr26",
75 "danifranco",
76 "esgomezm",
77 "fynnbe",
78 "githubuser2",
79 "iarganda",
80 "ivanhcenalmor",
81 "jansanrom",
82 "k-dominik",
83 "lenkaback",
84 "oeway",
85}
86N_KNOWN_GH_USERS = len(KNOWN_GH_USERS)
87KNOWN_INVALID_GH_USERS: Set[str] = {"arratemunoz", "lmescu"}
88N_KNOWN_INVALID_GH_USERS = len(KNOWN_INVALID_GH_USERS)