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
Feat: support script files #330
Merged
SylvainCorlay
merged 2 commits into
voila-dashboards:master
from
maartenbreddels:feat_support_script_files
Aug 28, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
import pytest | ||
|
||
TEST_XEUS_CLING = os.environ.get('VOILA_TEST_XEUS_CLING', '') == '1' | ||
|
||
|
||
@pytest.fixture | ||
def cpp_file_url(base_url): | ||
return base_url + "/voila/render/print.xcpp" | ||
|
||
|
||
@pytest.fixture | ||
def voila_args_extra(): | ||
return ['--VoilaConfiguration.extension_language_mapping={".xcpp": "C++11"}'] | ||
|
||
|
||
@pytest.fixture | ||
def voila_args(notebook_directory, voila_args_extra): | ||
return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra | ||
|
||
|
||
@pytest.mark.skipif(not TEST_XEUS_CLING, reason='opt in to avoid having to install xeus-cling') | ||
@pytest.mark.gen_test | ||
def test_non_existing_kernel(http_client, cpp_file_url): | ||
response = yield http_client.fetch(cpp_file_url) | ||
assert response.code == 200 | ||
assert 'Hello voila, from c++' in response.body.decode('utf-8') |
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,15 +1,40 @@ | ||
# test serving a notebook | ||
# test serving a notebook or python/c++ notebook | ||
import os | ||
import pytest | ||
|
||
TEST_XEUS_CLING = os.environ.get('VOILA_TEST_XEUS_CLING', '') == '1' | ||
|
||
|
||
@pytest.fixture | ||
def voila_args(notebook_directory, voila_args_extra): | ||
return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra | ||
|
||
|
||
@pytest.mark.gen_test | ||
def test_hello_world(http_client, print_notebook_url): | ||
def test_print(http_client, print_notebook_url): | ||
print(print_notebook_url) | ||
response = yield http_client.fetch(print_notebook_url) | ||
assert response.code == 200 | ||
assert 'Hi Voila' in response.body.decode('utf-8') | ||
|
||
|
||
@pytest.fixture | ||
def voila_args_extra(): | ||
return ['--VoilaConfiguration.extension_language_mapping={".py": "python"}'] | ||
|
||
|
||
@pytest.mark.gen_test | ||
def test_print_py(http_client, print_notebook_url): | ||
print(print_notebook_url) | ||
response = yield http_client.fetch(print_notebook_url.replace('ipynb', 'py')) | ||
assert response.code == 200 | ||
assert 'Hi Voila' in response.body.decode('utf-8') | ||
|
||
|
||
@pytest.mark.skipif(not TEST_XEUS_CLING, reason='opt in to avoid having to install xeus-cling') | ||
@pytest.mark.gen_test | ||
def test_print_julia_notebook(http_client, print_notebook_url): | ||
print(print_notebook_url) | ||
response = yield http_client.fetch(print_notebook_url.replace('.ipynb', '_cpp.ipynb')) | ||
assert response.code == 200 | ||
assert 'Hi Voila, from c++' in response.body.decode('utf-8') |
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,22 @@ | ||
# test tree rendering | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def voila_args(notebook_directory, voila_args_extra): | ||
return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra | ||
|
||
|
||
@pytest.fixture | ||
def voila_args_extra(): | ||
return ['--VoilaConfiguration.extension_language_mapping={".xcpp": "C++11"}'] | ||
|
||
|
||
@pytest.mark.gen_test | ||
def test_tree(http_client, base_url): | ||
response = yield http_client.fetch(base_url) | ||
assert response.code == 200 | ||
text = response.body.decode('utf-8') | ||
assert 'print.ipynb' in text, 'tree handler should render ipynb files' | ||
assert 'print.xcpp' in text, 'tree handler should render xcpp files (due to extension_language_mapping)' | ||
assert 'print.py' not in text, 'tree handler should not render .py files (due to extension_language_mapping)' |
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,15 @@ | ||
# --- | ||
# jupyter: | ||
# jupytext: | ||
# text_representation: | ||
# extension: .py | ||
# format_name: light | ||
# format_version: '1.4' | ||
# jupytext_version: 1.2.1 | ||
# kernelspec: | ||
# display_name: Python 3 | ||
# language: python | ||
# name: python | ||
# --- | ||
|
||
print('Hi Voila!') |
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,23 @@ | ||
// --- | ||
// jupyter: | ||
// jupytext: | ||
// text_representation: | ||
// extension: .cpp | ||
// format_name: light | ||
// format_version: '1.4' | ||
// jupytext_version: 1.2.1 | ||
// kernelspec: | ||
// display_name: C++11 | ||
// language: C++11 | ||
// name: xcpp11 | ||
// --- | ||
|
||
|
||
// this is not a valid .cpp file, since it does not have a main() | ||
// however, we can ask voila to execute this by using the xeus-cling kernel | ||
// or relying on jupytext | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
cout << "Hello voila, from c++"; |
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,39 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#include <iostream>\n", | ||
"using namespace std;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"cout << \"Hi Voila, from c++\";" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "C++11", | ||
"language": "C++11", | ||
"name": "xcpp11" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "text/x-c++src", | ||
"file_extension": ".cpp", | ||
"mimetype": "text/x-c++src", | ||
"name": "c++", | ||
"version": "-std=c++11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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,27 @@ | ||
import os | ||
import pytest | ||
|
||
TEST_XEUS_CLING = os.environ.get('VOILA_TEST_XEUS_CLING', '') == '1' | ||
|
||
|
||
@pytest.fixture | ||
def cpp_file_url(base_url): | ||
return base_url + "/voila/render/print.xcpp" | ||
|
||
|
||
@pytest.fixture | ||
def jupyter_server_args_extra(): | ||
return ['--VoilaConfiguration.extension_language_mapping={".xcpp": "C++11"}'] | ||
|
||
|
||
@pytest.fixture | ||
def voila_args(notebook_directory, voila_args_extra): | ||
return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra | ||
|
||
|
||
@pytest.mark.skipif(not TEST_XEUS_CLING, reason='opt in to avoid having to install xeus-cling') | ||
@pytest.mark.gen_test | ||
def test_non_existing_kernel(http_client, cpp_file_url): | ||
response = yield http_client.fetch(cpp_file_url) | ||
assert response.code == 200 | ||
assert 'Hello voila, from c++' in response.body.decode('utf-8') |
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,22 @@ | ||
# test tree rendering | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def voila_args(notebook_directory, voila_args_extra): | ||
return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra | ||
|
||
|
||
@pytest.fixture | ||
def jupyter_server_args_extra(): | ||
return ['--VoilaConfiguration.extension_language_mapping={".xcpp": "C++11"}'] | ||
|
||
|
||
@pytest.mark.gen_test | ||
def test_tree(http_client, base_url): | ||
response = yield http_client.fetch(base_url+'/voila/tree') | ||
assert response.code == 200 | ||
text = response.body.decode('utf-8') | ||
assert 'print.ipynb' in text, 'tree handler should render ipynb files' | ||
assert 'print.xcpp' in text, 'tree handler should render xcpp files (due to extension_language_mapping)' | ||
assert 'print.py' not in text, 'tree handler should not render .py files (due to extension_language_mapping)' |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe later after adding support for the progressive rendering (#133) there could be more than one cell created, from cell delimiters such as
%%
or# In[1]:
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this could again be a configurable, mapping from file extension to regex. I'd say not now right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed let's do that later (we can open an issue to track it).