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

Adding scala support to jupytext extension #253

Merged
merged 2 commits into from
Jun 13, 2019
Merged
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions jupytext/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Languages that may appear as magic instructions in Python notebooks
_JUPYTER_LANGUAGES = ['R', 'bash', 'sh', 'python', 'python2', 'python3', 'javascript', 'js', 'perl',
'html', 'latex', 'markdown', 'pypy', 'ruby', 'script', 'svg', 'writefile',
'matlab', 'octave', 'idl']
'matlab', 'octave', 'idl', 'scala']
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should add 'scala' here only if there exists a jupyter magic command with the same name. Is that the case? Do you see any trouble with scala notebooks represented as Markdown files when you don't add 'scala' here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello mwouts,

thank you for your fast reply.

When we do not define scala in the list of _JUPYTER_LANGUAGES, then *.scala files can not be opened as a notebook in Jupyterhub. You are limited to work only on source files...
image

Copy link
Owner

@mwouts mwouts Jun 12, 2019

Choose a reason for hiding this comment

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

You're welcome.

Well the classification of .scala files as notebooks comes from having added a .scala entry in the _SCRIPT_EXTENSIONS dictionary, not from JUPYTER_LANGUAGES.

I have found no %%scala magic in Python notebooks. The sparkmagic extension does provide %%sql and %%spark, but not %%scala - If you'd like, we could add sql and spark (instead of scala) to JUPYTER_LANGUAGES.

Do you think you will be able to contribute a sample scala notebook (does not need to be complex)? It should go to tests/notebooks/ipynb_scala, and then you will have to modify tests/test_mirror.py to add the following:

@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_scala'))
def test_ipynb_to_scala(nb_file):
    assert_conversion_same_as_mirror(nb_file, 'scala', 'ipynb_to_script')


@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_scala'))
def test_ipynb_to_scala_percent(nb_file):
    assert_conversion_same_as_mirror(nb_file, 'scala:percent', 'ipynb_to_percent')

Running the tests will generate the text representations - I need your help here to make sure these are legitimate scala files! Please let me know if you need more details. And thanks again for your contribution!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a simple scala notebook to see if the corresponding tests work...

We are using the Apache Toree plugin (https://toree.incubator.apache.org/), which have a lot of scala magics:
https://github.com/apache/incubator-toree/blob/master/etc/examples/notebooks/magic-tutorial.ipynb


# Supported file extensions (and languages)
# Please add more languages here (and add a few tests) - see CONTRIBUTING.md
Expand All @@ -20,7 +20,8 @@
'.m': {'language': 'matlab', 'comment': '%'},
'.pro': {'language': 'idl', 'comment': ';'},
'.js': {'language': 'javascript', 'comment': '//'},
'.ts': {'language': 'typescript', 'comment': '//'}}
'.ts': {'language': 'typescript', 'comment': '//'},
'.scala': {'language': 'scala', 'comment': '//'}}

_COMMENT_CHARS = [_SCRIPT_EXTENSIONS[ext]['comment'] for ext in _SCRIPT_EXTENSIONS if
_SCRIPT_EXTENSIONS[ext]['comment'] != '#']
Expand Down