Skip to content

Commit 2745f6e

Browse files
Moved imports to lower level
1 parent 109ae85 commit 2745f6e

7 files changed

Lines changed: 28 additions & 24 deletions

File tree

src/sap_cloud_sdk/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
# SAP Cloud SDK for Python
22

33
from sap_cloud_sdk.core.bootstrap import bootstrap, TelemetryConfig
4-
from sap_cloud_sdk.core.runtime_context._registry import Adapter, get_framework_adapters
5-
from sap_cloud_sdk.core.telemetry.instrumentation._registry import (
6-
Library,
7-
get_instrumented_libraries,
8-
)
94

105
__all__ = [
11-
"Adapter",
126
"bootstrap",
13-
"get_framework_adapters",
14-
"get_instrumented_libraries",
15-
"Library",
167
"TelemetryConfig",
178
]

src/sap_cloud_sdk/core/runtime_context/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
TRIGGER_TYPE,
3333
)
3434
from sap_cloud_sdk.core.runtime_context._protocol import ContextProvider
35-
from sap_cloud_sdk.core.runtime_context._registry import FrameworkAdapter, register
35+
from sap_cloud_sdk.core.runtime_context._registry import (
36+
Adapter,
37+
FrameworkAdapter,
38+
get_attached_adapters,
39+
register,
40+
)
3641
from sap_cloud_sdk.core.runtime_context.providers import (
3742
DWCContextProvider,
3843
IASContextProvider,
@@ -46,6 +51,7 @@
4651
import sap_cloud_sdk.core.runtime_context.adapters # noqa: F401
4752

4853
__all__ = [
54+
"Adapter",
4955
"APP_TENANT_ID",
5056
"ContextKey",
5157
"ContextProvider",
@@ -54,6 +60,7 @@
5460
"DWCContextProvider",
5561
"FEATURE_TOGGLES",
5662
"FrameworkAdapter",
63+
"get_attached_adapters",
5764
"GLOBAL_TENANT_ID",
5865
"IASContextProvider",
5966
"RuntimeContext",

src/sap_cloud_sdk/core/runtime_context/_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def record_attached(name: Adapter) -> None:
3737
_attached.append(name)
3838

3939

40-
def get_framework_adapters() -> List[Adapter]:
40+
def get_attached_adapters() -> List[Adapter]:
4141
"""Return the adapters attached via bootstrap().
4242
4343
Each entry corresponds to one :func:`~sap_cloud_sdk.bootstrap` call that

src/sap_cloud_sdk/core/runtime_context/user-guide.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ editing `bootstrap`.
202202
### Adding a new framework or invocation source
203203

204204
```python
205-
from sap_cloud_sdk import Adapter
206205
from sap_cloud_sdk.core.runtime_context import (
206+
Adapter,
207207
ContextProvider,
208208
FrameworkAdapter,
209209
register,
@@ -233,18 +233,18 @@ register(FlaskContextAdapter())
233233

234234
## Introspection
235235

236-
Use `get_framework_adapters()` to check which framework adapters have been attached at runtime:
236+
Use `get_attached_adapters()` to check which framework adapters have been attached at runtime:
237237

238238
```python
239-
from sap_cloud_sdk import Adapter, get_framework_adapters
239+
from sap_cloud_sdk.core.runtime_context import Adapter, get_attached_adapters
240240

241-
get_framework_adapters() # -> [Adapter.STARLETTE] after bootstrap(app), [] before
241+
get_attached_adapters() # -> [Adapter.STARLETTE] after bootstrap(app), [] before
242242
```
243243

244244
This is useful for modules that need to fail fast if their required framework was never bootstrapped:
245245

246246
```python
247-
if Adapter.STARLETTE not in get_framework_adapters():
247+
if Adapter.STARLETTE not in get_attached_adapters():
248248
raise RuntimeError(
249249
"This client requires Starlette to be bootstrapped. "
250250
"Call bootstrap(app) with your Starlette/FastAPI app."

src/sap_cloud_sdk/core/telemetry/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
ExtensionContextLogFilter,
5757
)
5858
from sap_cloud_sdk.core.telemetry.middleware import TelemetryMiddleware
59+
from sap_cloud_sdk.core.telemetry.instrumentation._registry import (
60+
Library,
61+
get_instrumented_libraries,
62+
)
5963

6064
__all__ = [
6165
"Module",
@@ -103,6 +107,8 @@
103107
"emit_extensions_summary_span",
104108
"ExtensionContextLogFilter",
105109
"TelemetryMiddleware",
110+
"Library",
111+
"get_instrumented_libraries",
106112
]
107113

108114
try:

src/sap_cloud_sdk/core/telemetry/user-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ The SDK ships `opentelemetry-instrumentation-*` packages for all of the above as
8383
Use `get_instrumented_libraries()` to query which libraries were actually patched at runtime:
8484

8585
```python
86-
from sap_cloud_sdk import Library, get_instrumented_libraries
86+
from sap_cloud_sdk.core.telemetry import Library, get_instrumented_libraries
8787

8888
get_instrumented_libraries() # -> [Library.HTTPX, Library.SQLALCHEMY, ...] after auto_instrument(), [] before
8989
```

tests/core/unit/runtime_context/test_runtime_context.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
)
2828
from sap_cloud_sdk.core.runtime_context._registry import (
2929
Adapter,
30-
get_framework_adapters,
30+
get_attached_adapters,
3131
record_attached,
3232
)
3333
from sap_cloud_sdk.core.runtime_context.providers._ias import (
@@ -440,7 +440,7 @@ def test_single_context_passthrough(self):
440440

441441

442442
# ---------------------------------------------------------------------------
443-
# get_framework_adapters
443+
# get_attached_adapters
444444
# ---------------------------------------------------------------------------
445445

446446

@@ -456,19 +456,19 @@ def teardown_method(self):
456456
registry_mod._attached.extend(self._original)
457457

458458
def test_empty_before_bootstrap(self):
459-
assert get_framework_adapters() == []
459+
assert get_attached_adapters() == []
460460

461461
def test_records_name_after_record_attached(self):
462462
record_attached(Adapter.STARLETTE)
463-
assert get_framework_adapters() == [Adapter.STARLETTE]
463+
assert get_attached_adapters() == [Adapter.STARLETTE]
464464

465465
def test_multiple_calls_accumulate(self):
466466
record_attached(Adapter.STARLETTE)
467467
record_attached(Adapter.STARLETTE) # idempotent
468-
assert get_framework_adapters() == [Adapter.STARLETTE]
468+
assert get_attached_adapters() == [Adapter.STARLETTE]
469469

470470
def test_returns_copy(self):
471471
record_attached(Adapter.STARLETTE)
472-
snapshot = get_framework_adapters()
472+
snapshot = get_attached_adapters()
473473
snapshot.clear()
474-
assert get_framework_adapters() == [Adapter.STARLETTE]
474+
assert get_attached_adapters() == [Adapter.STARLETTE]

0 commit comments

Comments
 (0)