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