8Provide a version-compatibility check between OCT and the ``oc_diagnostics``
13- Define the supported ``oc_diagnostics`` version range.
14- Query the installed ``oc_diagnostics`` version via ``importlib.metadata``.
15- Return a human-readable warning or info string when the installed version
16 is out of range or absent; return ``None`` when compatible.
28- Must not import ``oc_diagnostics`` directly; ``_dbg`` arrives through
29 the fail-soft ``oct.core.diagnostics`` shim, and the installed version
30 is read from metadata rather than by importing the package.
31- Must not require the ``packaging`` library; uses tuple-based comparison.
32- Must be safe to call when ``oc_diagnostics`` is not installed.
36- oct.core.diagnostics (_dbg structured logger)
39from __future__
import annotations
40from oct.core.diagnostics
import _dbg
42_OC_DIAGNOSTICS_COMPAT = {
"min":
"2.0.0",
"max":
"3.0.0"}
46 """Convert a dotted version string to a tuple of ints for comparison."""
48 for segment
in v.split(
"."):
55 parts.append(int(digits)
if digits
else 0)
61 Check whether the installed ``oc_diagnostics`` version is within the
67 A warning/info message if out of range or not installed.
68 ``None`` if the version is compatible.
70 func =
"check_oc_diagnostics_compat"
71 _dbg(
"OCT-CORE", func,
"checking the installed oc_diagnostics version", 3)
73 from importlib.metadata
import version
as _pkg_version
74 installed = _pkg_version(
"oc_diagnostics")
77 "Info: oc_diagnostics is not installed. "
78 "Projects created by OCT require oc_diagnostics at runtime."
85 except (ValueError, TypeError):
86 return f
"Warning: Could not parse oc_diagnostics version '{installed}'."
90 f
"Warning: oc_diagnostics {installed} is below the minimum "
91 f
"supported version ({_OC_DIAGNOSTICS_COMPAT['min']}). "
92 f
"Consider upgrading."
97 f
"Warning: oc_diagnostics {installed} is at or above the maximum "
98 f
"tested version ({_OC_DIAGNOSTICS_COMPAT['max']}). "
99 f
"OCT may need an update."
tuple[int,...] _parse_version_tuple(str v)
str|None check_oc_diagnostics_compat()