From 6b9915a3ee26eed77e3a609ed88e13beac80b68c Mon Sep 17 00:00:00 2001 From: Tobias Frischholz Date: Wed, 12 Jun 2019 10:35:17 +0200 Subject: [PATCH 1/2] Adding scala support to jupytext extension --- jupytext/languages.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jupytext/languages.py b/jupytext/languages.py index 149379760..7467eaf9e 100644 --- a/jupytext/languages.py +++ b/jupytext/languages.py @@ -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'] # Supported file extensions (and languages) # Please add more languages here (and add a few tests) - see CONTRIBUTING.md @@ -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'] != '#'] From a07591d8be46684f05e1c8c1ec7e11d3c5caa1a1 Mon Sep 17 00:00:00 2001 From: Tobias Frischholz Date: Thu, 13 Jun 2019 08:53:25 +0200 Subject: [PATCH 2/2] Adding scala test notebook for better testing support --- .../ipynb_scala/simple_scala_notebook.ipynb | 75 +++++++++++++++++++ .../simple_scala_notebook.scala | 19 +++++ .../simple_scala_notebook.scala | 19 +++++ tests/test_mirror.py | 12 +++ 4 files changed, 125 insertions(+) create mode 100644 tests/notebooks/ipynb_scala/simple_scala_notebook.ipynb create mode 100644 tests/notebooks/mirror/ipynb_to_percent/simple_scala_notebook.scala create mode 100644 tests/notebooks/mirror/ipynb_to_script/simple_scala_notebook.scala diff --git a/tests/notebooks/ipynb_scala/simple_scala_notebook.ipynb b/tests/notebooks/ipynb_scala/simple_scala_notebook.ipynb new file mode 100644 index 000000000..f8d6a3b16 --- /dev/null +++ b/tests/notebooks/ipynb_scala/simple_scala_notebook.ipynb @@ -0,0 +1,75 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "defined object SampleObject\n", + "result = 3\n" + ] + }, + "metadata": {}, + "output_type": "display_data", + "source": "user" + }, + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "// This is just a simple scala notebook\n", + "\n", + "object SampleObject {\n", + " def calculation(x: Int, y: Int): Int = x + y\n", + "}\n", + "\n", + "val result = SampleObject.calculation(1, 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "30\n" + ] + } + ], + "source": [ + "println(result * 10)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Apache Toree - Scala", + "language": "scala", + "name": "apache_toree_scala" + }, + "language_info": { + "codemirror_mode": "text/x-scala", + "file_extension": ".scala", + "mimetype": "text/x-scala", + "name": "scala", + "pygments_lexer": "scala", + "version": "2.11.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tests/notebooks/mirror/ipynb_to_percent/simple_scala_notebook.scala b/tests/notebooks/mirror/ipynb_to_percent/simple_scala_notebook.scala new file mode 100644 index 000000000..bf025876b --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_percent/simple_scala_notebook.scala @@ -0,0 +1,19 @@ +// --- +// jupyter: +// kernelspec: +// display_name: Apache Toree - Scala +// language: scala +// name: apache_toree_scala +// --- + +// %% +// This is just a simple scala notebook + +object SampleObject { + def calculation(x: Int, y: Int): Int = x + y +} + +val result = SampleObject.calculation(1, 2) + +// %% +println(result * 10) diff --git a/tests/notebooks/mirror/ipynb_to_script/simple_scala_notebook.scala b/tests/notebooks/mirror/ipynb_to_script/simple_scala_notebook.scala new file mode 100644 index 000000000..631ac90ef --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_script/simple_scala_notebook.scala @@ -0,0 +1,19 @@ +// --- +// jupyter: +// kernelspec: +// display_name: Apache Toree - Scala +// language: scala +// name: apache_toree_scala +// --- + +// + +// This is just a simple scala notebook + +object SampleObject { + def calculation(x: Int, y: Int): Int = x + y +} + +val result = SampleObject.calculation(1, 2) +// - + +println(result * 10) diff --git a/tests/test_mirror.py b/tests/test_mirror.py index a1b87cc8f..5e26bf1d2 100644 --- a/tests/test_mirror.py +++ b/tests/test_mirror.py @@ -4,10 +4,12 @@ """ import os + import mock import pytest from nbformat.v4.nbbase import new_notebook from testfixtures import compare + import jupytext from jupytext.compare import compare_notebooks, combine_inputs_with_outputs from jupytext.formats import long_form_one_format @@ -315,3 +317,13 @@ def test_ipynb_to_ts(nb_file): @pytest.mark.parametrize('nb_file', list_notebooks('ipynb_ts')) def test_ipynb_to_ts_percent(nb_file): assert_conversion_same_as_mirror(nb_file, 'ts:percent', 'ipynb_to_percent') + + +@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')