-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
12,110 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "6385f929-aa4c-4f03-83c9-41e3bc95af83", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"os.environ[\"TRAME_DISABLE_V3_WARNING\"] = \"1\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "9edec8b3-a309-4da7-824e-da1443d07b85", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from trame.app import get_server\n", | ||
"\n", | ||
"server = get_server()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "9b34d663-dcdd-40f0-8966-b6d6578c1932", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from trame.ui.vuetify import SinglePageLayout\n", | ||
"\n", | ||
"layout = SinglePageLayout(server)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "cdbb028f-4da9-4abe-a198-ecfa555b9e23", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from trame.widgets import vuetify, html\n", | ||
"\n", | ||
"with layout:\n", | ||
" with layout.toolbar as tb:\n", | ||
" vuetify.VSpacer()\n", | ||
" vuetify.VBtn(\"Hello\")\n", | ||
" with layout.content:\n", | ||
" with vuetify.VContainer(classes=\"fluid fill-height pa-0 ma-0\"):\n", | ||
" html.Div(\"Hello world\", style=\"background: red\")\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "c971b380-3145-47ac-b9ca-1ae9dc0649d4", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"<Future pending>" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"server.ready" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "883d7c0c-ca78-491b-838c-ce5e445e5736", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"server.start(exec_mode=\"task\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "b275ef23-d3b6-4814-8eb2-7503514c7a8f", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"<Future pending>" | ||
] | ||
}, | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"server.ready" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "56158e6b-a230-436e-8bdb-f03bbba94c5c", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div>\n", | ||
" The server is not running. Before displaying a trame layout you should await it to make sure it is ready.\n", | ||
" You should run the following code before displaying a layout.\n", | ||
" <pre style=\"padding: 5px; border: solid 1px rgb(224,224,224); background: rgb(245,245,245);\">await layout.ready</pre>\n", | ||
" </div>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"layout" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "397dc56d-5202-4c5c-bce3-3e7952c7d226", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,8 @@ | |
https://jupyterlab.readthedocs.io/en/stable/developer/css.html | ||
*/ | ||
|
||
.trame-iframe { | ||
border: none; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,52 @@ | ||
import json | ||
import os | ||
import tempfile | ||
from pathlib import Path | ||
|
||
from jupyter_server.base.handlers import APIHandler | ||
from jupyter_server.utils import url_path_join | ||
import tornado | ||
|
||
class RouteHandler(APIHandler): | ||
# The following decorator should be present on all verb methods (head, get, post, | ||
# patch, put, delete, options) to ensure only authorized user can request the | ||
# Jupyter server | ||
@tornado.web.authenticated | ||
def get(self): | ||
self.finish(json.dumps({ | ||
"data": "This is /trame-jupyter-server/get-example endpoint!" | ||
})) | ||
from trame.tools.www import StaticContentGenerator | ||
|
||
# Static directory to serve | ||
TRAME_STATIC_WWW = tempfile.mkdtemp() | ||
|
||
# Change default backend for generic | ||
# os.environ["TRAME_BACKEND"] = "generic" # FIXME - Uncomment when ready... | ||
|
||
|
||
# Generate trame static content | ||
def write_static_www(*modules): | ||
for client_type in ["vue2", "vue3"]: | ||
generator = StaticContentGenerator() | ||
generator.client_type = client_type | ||
generator.enable_all() | ||
if len(modules) and modules[0]: | ||
generator.enable_modules(*modules) | ||
generator.write(Path(TRAME_STATIC_WWW) / client_type) | ||
|
||
|
||
# Generate static content | ||
write_static_www(*os.environ.get("TRAME_MODULES", "").split(",")) | ||
|
||
|
||
# class RouteHandler(APIHandler): | ||
# # The following decorator should be present on all verb methods (head, get, post, | ||
# # patch, put, delete, options) to ensure only authorized user can request the | ||
# # Jupyter server | ||
# @tornado.web.authenticated | ||
# def get(self): | ||
# self.finish(json.dumps({ | ||
# "data": "This is /trame-jupyter-server/get-example endpoint!" | ||
# })) | ||
|
||
|
||
def setup_handlers(web_app): | ||
host_pattern = ".*$" | ||
|
||
base_url = web_app.settings["base_url"] | ||
route_pattern = url_path_join(base_url, "trame-jupyter-server", "get-example") | ||
handlers = [(route_pattern, RouteHandler)] | ||
static = url_path_join(base_url, "trame-jupyter-server", "(.*)") | ||
handlers = [ | ||
(static, tornado.web.StaticFileHandler, dict(path=TRAME_STATIC_WWW)), | ||
] | ||
web_app.add_handlers(host_pattern, handlers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
from trame_jupyter_server.handlers import TRAME_STATIC_WWW | ||
|
||
|
||
async def test_get_example(jp_fetch): | ||
# When | ||
response = await jp_fetch("trame-jupyter-server", "get-example") | ||
response = await jp_fetch("trame-jupyter-server", "vue2", "index.html") | ||
|
||
# Then | ||
assert response.code == 200 | ||
payload = json.loads(response.body) | ||
assert payload == { | ||
"data": "This is /trame-jupyter-server/get-example endpoint!" | ||
} | ||
txt_content = response.body | ||
source_content = (Path(TRAME_STATIC_WWW) / "vue2" / "index.html").read_text("utf-8") | ||
assert txt_content == source_content |
Oops, something went wrong.