Skip to content

Commit 7a7c28b

Browse files
committed
ExtensionContext.load_extensions(): list[Extension] --> ExtensionContext.load(): ExtensionContext
1 parent 851cfd1 commit 7a7c28b

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

dashipy/dashipy/demo/server.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ def make_app():
108108
with open("my-config.yaml") as f:
109109
server_config = yaml.load(f, yaml.SafeLoader)
110110

111-
# Parse panel renderers
112-
extensions = ExtensionContext.load_extensions(server_config.get("extensions", []))
113-
114111
# Create app
115112
app = tornado.web.Application(
116113
[
@@ -120,7 +117,11 @@ def make_app():
120117
(r"/dashi/callback", CallbackHandler),
121118
]
122119
)
123-
app.settings[DASHI_CONTEXT_KEY] = ExtensionContext(Context(), extensions)
120+
121+
# Load extensions
122+
ext_ctx = ExtensionContext.load(Context(), server_config.get("extensions", []))
123+
app.settings[DASHI_CONTEXT_KEY] = ext_ctx
124+
124125
return app
125126

126127

dashipy/dashipy/extensioncontext.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import importlib
22
from typing import Any
33

4+
import sys
5+
46
from dashipy import Extension, Contribution
57

68

@@ -31,7 +33,22 @@ def contributions(self) -> dict[str, list[Contribution]]:
3133
return self._contributions
3234

3335
@classmethod
34-
def load_extensions(cls, extension_refs: list[str]) -> list[Extension]:
36+
def load(
37+
cls,
38+
app_ctx: Any,
39+
extension_refs: list[str],
40+
) -> "ExtensionContext":
41+
"""Create a new extension context from the given application context
42+
and list of extension references.
43+
44+
Args:
45+
app_ctx: Application context object passed to a contribution's
46+
layout factory and callback functions.
47+
extension_refs: Extension references where each item must
48+
have the form ``"module.attribute"``.
49+
Returns:
50+
A new extension context.
51+
"""
3552
extensions: list[Extension] = []
3653
for ext_ref in extension_refs:
3754
try:
@@ -47,4 +64,4 @@ def load_extensions(cls, extension_refs: list[str]) -> list[Extension]:
4764
f" but was {type(extension).__qualname__!r}"
4865
)
4966
extensions.append(extension)
50-
return extensions
67+
return ExtensionContext(app_ctx, extensions)

0 commit comments

Comments
 (0)