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