Skip to content

Commit d123cd1

Browse files
committed
set draft of customlabextension
1 parent 0ffd12a commit d123cd1

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

voila/configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class VoilaConfiguration(traitlets.config.Configurable):
3535
template = Unicode(
3636
"lab", config=True, allow_none=True, help=("template name to be used by voila.")
3737
)
38+
labextensions_url = Unicode("", config=True, help=("Custom lab extensions url."))
3839
classic_tree = Bool(
3940
False,
4041
config=True,

voila/handler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ async def get_generator(self, path=None):
115115

116116
template_arg = self.get_argument("template", None)
117117
theme_arg = self.get_argument("theme", None)
118+
labextensions_url = self.get_argument("labextensions_url", None)
119+
120+
# Set the labextension_url if it is provided
121+
if labextensions_url:
122+
self.voila_configuration.labextensions_url = labextensions_url
118123

119124
# Compose reply
120125
self.set_header("Content-Type", "text/html")

voila/utils.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
#############################################################################
99

1010
import asyncio
11+
import io
1112
import json
1213
import os
1314
import sys
15+
import tempfile
1416
import threading
1517
import warnings
1618
from copy import deepcopy
1719
from functools import partial
1820
from pathlib import Path
1921
from typing import Awaitable, Dict, List
22+
import zipfile
2023

24+
import requests
2125
import websockets
2226
from jupyter_core.paths import jupyter_path
2327
from jupyter_server.config_manager import recursive_update
@@ -97,24 +101,47 @@ def get_page_config(base_url, settings, log, voila_configuration: VoilaConfigura
97101
"baseUrl": base_url,
98102
"terminalsAvailable": False,
99103
"fullStaticUrl": url_path_join(base_url, "voila/static"),
100-
"fullLabextensionsUrl": url_path_join(base_url, "voila/labextensions"),
101104
"extensionConfig": voila_configuration.extension_config,
105+
"fullLabextensionsUrl": url_path_join(
106+
voila_configuration.labextensions_url, "labextensions"
107+
)
108+
or url_path_join(base_url, "voila/labextensions"),
102109
}
110+
103111
mathjax_config = settings.get("mathjax_config", "TeX-AMS_CHTML-full,Safe")
104112
mathjax_url = settings.get(
105113
"mathjax_url", "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js"
106114
)
107115
page_config.setdefault("mathjaxConfig", mathjax_config)
108116
page_config.setdefault("fullMathjaxUrl", mathjax_url)
109-
labextensions_path = jupyter_path("labextensions")
110-
111-
recursive_update(
112-
page_config,
113-
gpc(
114-
labextensions_path,
115-
logger=log,
116-
),
117+
print("########### page_config", page_config)
118+
119+
# If I want to do use the existing url and the custom, the the server here should
120+
# have the 'download_all_extensions' endpoint...
121+
122+
download_extensions_url = url_path_join(
123+
page_config.get("fullLabextensionsUrl"), "download_all_extensions"
117124
)
125+
126+
response = requests.get(download_extensions_url)
127+
response.raise_for_status()
128+
129+
with tempfile.TemporaryDirectory() as labextensions_temp_path:
130+
131+
# Extract the ZIP file into the temporary directory
132+
with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
133+
zip_ref.extractall(labextensions_temp_path)
134+
135+
# I need to replace labextensions_temp_path with the actual result of
136+
recursive_update(
137+
page_config,
138+
gpc(
139+
[labextensions_temp_path],
140+
logger=log,
141+
),
142+
)
143+
144+
print("################Updatedsss page_config", page_config)
118145
disabled_extensions = [
119146
"@voila-dashboards/jupyterlab-preview",
120147
"@jupyter/collaboration-extension",

0 commit comments

Comments
 (0)