Option C oc_diagnostics
Loading...
Searching...
No Matches
__init__.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# oc_diagnostics/__init__.py
4
5"""
6oc_diagnostics
7==============
8
9Purpose
10-------
11Package entry point for ``oc_diagnostics``. Exports the public runtime API
12so downstream projects can use a single import::
13
14 from oc_diagnostics import _dbg, init, apply_instrumentation
15
16Responsibilities
17----------------
18- Re-export ``_dbg``, ``DEBUG_LEVELS``, and ``init`` from ``unified_debug``.
19- Re-export ``apply_instrumentation`` from ``instrumentation_middleware`` when
20 Dash is installed; raise an actionable ``ImportError`` at call time when
21 it is not.
22- Re-export ``DiagnosticsMiddleware`` from ``fastapi_middleware`` when FastAPI
23 is installed; raise an actionable ``ImportError`` at call time when it is not.
24- Declare ``__all__`` so the public surface is explicit and IDE-discoverable.
25- Remain completely side-effect-free at import time.
26
27Diagnostics
28-----------
29Domain: GENERAL
30Levels:
31 L2 โ€” lifecycle
32 L3 โ€” semantic details
33 L4 โ€” deep tracing
34
35Contracts
36---------
37- Must not activate stream interception or exception hooks at import time.
38 Callers must call ``oc_diagnostics.init()`` explicitly.
39- Optional dependencies (Dash, FastAPI) must not be required for import.
40 Missing dependencies must only raise ``ImportError`` at call time.
41- ``__all__`` must list every symbol exported by this module.
42"""
43
44__version__ = "2.0.0"
45
46from typing import Any, NoReturn
47
48from .unified_debug import (
49 _dbg,
50 _adbg,
51 _dbg_assert,
52 DEBUG_LEVELS,
53 init,
54 set_debug_level,
55 set_global_setting,
56 dbg_timed,
57 dbg_scope,
58 dbg_profile,
59 dbg_trace,
60 dbg_metrics,
61)
62
63# Python logging integration (pure Python, always available)
64from .logging_handler import OcDiagnosticsHandler
65
66# Optional Dash integration (only if Dash is installed)
67try:
68 from .instrumentation_middleware import apply_instrumentation
69except ImportError:
70 # OI-14: explicit NoReturn type so static analysis tools report a clear
71 # "always raises" signature rather than an opaque "unknown return type".
72 def apply_instrumentation(*args: Any, **kwargs: Any) -> NoReturn: # type: ignore[misc]
73 raise ImportError(
74 "apply_instrumentation requires Dash. "
75 "Install it with: pip install oc_diagnostics[dash] "
76 "See INTEGRATION_GUIDE.md for setup instructions." # OI-15
77 )
78
79# Optional FastAPI / ASGI integration
80try:
81 from .fastapi_middleware import DiagnosticsMiddleware
82except ImportError:
83 # OI-14: explicit NoReturn type so static analysis tools report a clear
84 # "always raises" signature rather than an opaque "unknown return type".
85 def DiagnosticsMiddleware(*args: Any, **kwargs: Any) -> NoReturn: # type: ignore[misc]
86 raise ImportError(
87 "DiagnosticsMiddleware could not be imported. "
88 "Install FastAPI support with: pip install oc_diagnostics[fastapi] "
89 "See INTEGRATION_GUIDE.md ยง10 for setup instructions." # OI-15
90 )
91
92__all__ = [
93 "_dbg",
94 "_adbg",
95 "_dbg_assert",
96 "DEBUG_LEVELS",
97 "init",
98 "set_debug_level",
99 "set_global_setting",
100 "dbg_timed",
101 "dbg_scope",
102 "dbg_profile",
103 "dbg_trace",
104 "dbg_metrics",
105 "OcDiagnosticsHandler",
106 "apply_instrumentation",
107 "DiagnosticsMiddleware",
108]
NoReturn DiagnosticsMiddleware(*Any args, **Any kwargs)
Definition __init__.py:85
NoReturn apply_instrumentation(*Any args, **Any kwargs)
Definition __init__.py:72