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`` at module level (avoids circular deps).
29- Must not require the ``packaging`` library; uses tuple-based comparison.
30- Must be safe to call when ``oc_diagnostics`` is not installed.
33from __future__
import annotations
35_OC_DIAGNOSTICS_COMPAT = {
"min":
"2.0.0",
"max":
"3.0.0"}
39 """Convert a dotted version string to a tuple of ints for comparison."""
41 for segment
in v.split(
"."):
48 parts.append(int(digits)
if digits
else 0)
54 Check whether the installed ``oc_diagnostics`` version is within the
60 A warning/info message if out of range or not installed.
61 ``None`` if the version is compatible.
64 from importlib.metadata
import version
as _pkg_version
65 installed = _pkg_version(
"oc_diagnostics")
68 "Info: oc_diagnostics is not installed. "
69 "Projects created by OCT require oc_diagnostics at runtime."
76 except (ValueError, TypeError):
77 return f
"Warning: Could not parse oc_diagnostics version '{installed}'."
81 f
"Warning: oc_diagnostics {installed} is below the minimum "
82 f
"supported version ({_OC_DIAGNOSTICS_COMPAT['min']}). "
83 f
"Consider upgrading."
88 f
"Warning: oc_diagnostics {installed} is at or above the maximum "
89 f
"tested version ({_OC_DIAGNOSTICS_COMPAT['max']}). "
90 f
"OCT may need an update."
tuple[int,...] _parse_version_tuple(str v)
str|None check_oc_diagnostics_compat()