-
Notifications
You must be signed in to change notification settings - Fork 524
reenable prelaunch-hook #724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e126df9
reenable prelaunch-hook
timkpaine cc0dc15
add docs
timkpaine 6179455
fix lint and indent issue
timkpaine 826a772
merge main
timkpaine dc6689a
pass handler down into hook
timkpaine 23bb681
add test, fix bug in passing tornado handler
timkpaine 5aad845
add papermill example and test
timkpaine 4a50cf1
Merge branch 'main' into prelaunch_hook
timkpaine 3baf57e
move papermill to test deps
alkasm de0918b
fix lint errors
timkpaine 9a1619f
bump ci
timkpaine 61f6d86
Update customize.rst
timkpaine 9e70cc7
bump ci
timkpaine e658bbe
Merge remote-tracking branch 'origin/prelaunch_hook' into prelaunch_hook
timkpaine 216595b
Merge branch 'main' into prelaunch_hook
timkpaine c9d2e1e
update prelaunch docs, switch from Any to Callable for prelaunch hook
timkpaine 20ab668
raise exception if incompatible preheat + prelaunch, make sure to ins…
timkpaine 8a095e7
Update docs
trungleduc 6f74474
Merge branch 'main' into prelaunch_hook
trungleduc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -54,6 +54,7 @@ test = | |
mock | ||
pytest | ||
pytest-tornasync | ||
papermill | ||
|
||
visual_test = | ||
jupyterlab~=3.0 | ||
|
This file contains hidden or 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,62 @@ | ||
# tests prelaunch hook config | ||
import pytest | ||
|
||
import os | ||
|
||
from urllib.parse import quote_plus | ||
|
||
BASE_DIR = os.path.dirname(__file__) | ||
|
||
|
||
@pytest.fixture | ||
def voila_notebook(notebook_directory): | ||
return os.path.join(notebook_directory, 'print_parameterized.ipynb') | ||
|
||
|
||
@pytest.fixture | ||
def voila_config(): | ||
def parameterize_with_papermill(req, notebook, cwd): | ||
import tornado | ||
|
||
# Grab parameters | ||
parameters = req.get_argument("parameters", {}) | ||
|
||
# try to convert to dict if not e.g. string/unicode | ||
if not isinstance(parameters, dict): | ||
try: | ||
parameters = tornado.escape.json_decode(parameters) | ||
except ValueError: | ||
parameters = None | ||
|
||
# if passed and a dict, use papermill to inject parameters | ||
if parameters and isinstance(parameters, dict): | ||
from papermill.parameterize import parameterize_notebook | ||
|
||
# setup for papermill | ||
# | ||
# these two blocks are done | ||
# to avoid triggering errors | ||
# in papermill's notebook | ||
# loading logic | ||
for cell in notebook.cells: | ||
if 'tags' not in cell.metadata: | ||
cell.metadata.tags = [] | ||
if "papermill" not in notebook.metadata: | ||
notebook.metadata.papermill = {} | ||
|
||
# Parameterize with papermill | ||
return parameterize_notebook(notebook, parameters) | ||
|
||
def config(app): | ||
app.prelaunch_hook = parameterize_with_papermill | ||
|
||
return config | ||
|
||
|
||
async def test_prelaunch_hook_papermill(http_server_client, base_url): | ||
url = base_url + '?parameters=' + quote_plus('{"name":"Parameterized_Variable"}') | ||
response = await http_server_client.fetch(url) | ||
assert response.code == 200 | ||
html_text = response.body.decode('utf-8') | ||
assert 'Hi Parameterized_Variable' in html_text | ||
assert 'test_template.css' not in html_text, "test_template should not be the default" |
This file contains hidden or 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,37 @@ | ||
# tests prelaunch hook config | ||
import pytest | ||
|
||
import os | ||
|
||
from nbformat import NotebookNode | ||
|
||
BASE_DIR = os.path.dirname(__file__) | ||
|
||
|
||
@pytest.fixture | ||
def voila_notebook(notebook_directory): | ||
return os.path.join(notebook_directory, 'print.ipynb') | ||
|
||
|
||
@pytest.fixture | ||
def voila_config(): | ||
def foo(req, notebook, cwd): | ||
argument = req.get_argument("test") | ||
notebook.cells.append(NotebookNode({ | ||
"cell_type": "code", | ||
"execution_count": 0, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": f"print(\"Hi prelaunch hook {argument}!\")\n" | ||
})) | ||
|
||
def config(app): | ||
app.prelaunch_hook = foo | ||
return config | ||
|
||
|
||
async def test_prelaunch_hook(http_server_client, base_url): | ||
response = await http_server_client.fetch(base_url + "?test=blerg", ) | ||
assert response.code == 200 | ||
assert 'Hi Voilà' in response.body.decode('utf-8') | ||
assert 'Hi prelaunch hook blerg' in response.body.decode('utf-8') |
This file contains hidden or 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,47 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"tags": [ | ||
"parameters" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"name = 'Voila'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print('Hi ' + name + '!')" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python" | ||
}, | ||
"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.7.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.