Skip to content
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 py files via jupytext #328

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ before_install:
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda info -a
- conda create -q -n test-environment -c conda-forge python=$PYTHON_VERSION jupyter_server==0.1.0 jupyterlab_pygments==0.1.0 pytest==3.10.1 nbconvert=5.5 pytest-cov nodejs flake8 ipywidgets matplotlib
- conda create -q -n test-environment -c conda-forge python=$PYTHON_VERSION jupyter_server==0.1.0 jupyterlab_pygments==0.1.0 pytest==3.10.1 nbconvert=5.5 pytest-cov nodejs flake8 ipywidgets matplotlib jupytext
- source activate test-environment
install:
- pip install ".[test]"
Expand Down
15 changes: 15 additions & 0 deletions tests/notebooks/print.py
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!')
11 changes: 10 additions & 1 deletion tests/server/execute_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@


@pytest.mark.gen_test
def test_hello_world(http_client, print_notebook_url):
def test_print(http_client, print_notebook_url):
response = yield http_client.fetch(print_notebook_url)
assert response.code == 200
html_text = response.body.decode('utf-8')
assert 'Hi Voila' in html_text
assert 'print' not in html_text, 'by default the source code should be stripped'
assert 'test_template.css' not in html_text, "test_template should not be the default"


@pytest.mark.gen_test
def test_print_py(http_client, print_notebook_url):
response = yield http_client.fetch(print_notebook_url.replace('ipynb', 'py'))
assert response.code == 200
html_text = response.body.decode('utf-8')
assert 'Hi Voila' in html_text
assert 'print' not in html_text, 'by default the source code should be stripped'
2 changes: 1 addition & 1 deletion voila/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# if the directory above us contains the following paths, it means we are installed in dev mode (pip install -e .)
DEV_MODE = os.path.exists(os.path.join(ROOT, '../setup.py')) and os.path.exists(os.path.join(ROOT, '../share'))

notebook_path_regex = r'(.*\.ipynb)'
notebook_path_regex = r'(.*\.(?:ipynb|py))'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we could get support for other languages for free here (Julia, R and so on)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I've added julia in #330, because I could test it. I didn't feel comfortable adding more. I also wonder if we should have a .* regex?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex was added because voila could only handle .ipynb files.

But if scripts (in different languages) are going to be supported, it probably make sense to switch back to .*. Otherwise we would have to maintain a white list of supported extensions.



def collect_template_paths(
Expand Down