Skip to content

Commit

Permalink
set draft of customlabextension
Browse files Browse the repository at this point in the history
  • Loading branch information
dfguerrerom committed Oct 6, 2024
1 parent 0ffd12a commit d123cd1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions voila/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class VoilaConfiguration(traitlets.config.Configurable):
template = Unicode(
"lab", config=True, allow_none=True, help=("template name to be used by voila.")
)
labextensions_url = Unicode("", config=True, help=("Custom lab extensions url."))
classic_tree = Bool(
False,
config=True,
Expand Down
5 changes: 5 additions & 0 deletions voila/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ async def get_generator(self, path=None):

template_arg = self.get_argument("template", None)
theme_arg = self.get_argument("theme", None)
labextensions_url = self.get_argument("labextensions_url", None)

# Set the labextension_url if it is provided
if labextensions_url:
self.voila_configuration.labextensions_url = labextensions_url

# Compose reply
self.set_header("Content-Type", "text/html")
Expand Down
45 changes: 36 additions & 9 deletions voila/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
#############################################################################

import asyncio
import io
import json
import os
import sys
import tempfile
import threading
import warnings
from copy import deepcopy
from functools import partial
from pathlib import Path
from typing import Awaitable, Dict, List
import zipfile

import requests
import websockets
from jupyter_core.paths import jupyter_path
from jupyter_server.config_manager import recursive_update
Expand Down Expand Up @@ -97,24 +101,47 @@ def get_page_config(base_url, settings, log, voila_configuration: VoilaConfigura
"baseUrl": base_url,
"terminalsAvailable": False,
"fullStaticUrl": url_path_join(base_url, "voila/static"),
"fullLabextensionsUrl": url_path_join(base_url, "voila/labextensions"),
"extensionConfig": voila_configuration.extension_config,
"fullLabextensionsUrl": url_path_join(
voila_configuration.labextensions_url, "labextensions"
)
or url_path_join(base_url, "voila/labextensions"),
}

mathjax_config = settings.get("mathjax_config", "TeX-AMS_CHTML-full,Safe")
mathjax_url = settings.get(
"mathjax_url", "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js"
)
page_config.setdefault("mathjaxConfig", mathjax_config)
page_config.setdefault("fullMathjaxUrl", mathjax_url)
labextensions_path = jupyter_path("labextensions")

recursive_update(
page_config,
gpc(
labextensions_path,
logger=log,
),
print("########### page_config", page_config)

# If I want to do use the existing url and the custom, the the server here should
# have the 'download_all_extensions' endpoint...

download_extensions_url = url_path_join(
page_config.get("fullLabextensionsUrl"), "download_all_extensions"
)

response = requests.get(download_extensions_url)
response.raise_for_status()

with tempfile.TemporaryDirectory() as labextensions_temp_path:

# Extract the ZIP file into the temporary directory
with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
zip_ref.extractall(labextensions_temp_path)

# I need to replace labextensions_temp_path with the actual result of
recursive_update(
page_config,
gpc(
[labextensions_temp_path],
logger=log,
),
)

print("################Updatedsss page_config", page_config)
disabled_extensions = [
"@voila-dashboards/jupyterlab-preview",
"@jupyter/collaboration-extension",
Expand Down

0 comments on commit d123cd1

Please sign in to comment.