From 45ad485858bcbaa07c1e3a246f2bbcd072d291cb Mon Sep 17 00:00:00 2001 From: Asko Soukka Date: Fri, 8 Nov 2019 20:29:48 +0200 Subject: [PATCH 1/6] Add Robot Framework (.robot) -language support --- jupytext/languages.py | 5 +- .../ipynb_robot/simple_robot_notebook.ipynb | 70 +++++++++++++++++++ tests/test_mirror.py | 10 +++ 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 tests/notebooks/ipynb_robot/simple_robot_notebook.ipynb diff --git a/jupytext/languages.py b/jupytext/languages.py index eb6114619..fc5c45990 100644 --- a/jupytext/languages.py +++ b/jupytext/languages.py @@ -3,7 +3,7 @@ # Jupyter magic commands that are also languages _JUPYTER_LANGUAGES = ['R', 'bash', 'sh', 'python', 'python2', 'python3', 'javascript', 'js', 'perl', 'html', 'latex', 'markdown', 'pypy', 'ruby', 'script', 'svg', - 'matlab', 'octave', 'idl', 'spark', 'sql'] + 'matlab', 'octave', 'idl', 'robotframework', 'spark', 'sql'] # Supported file extensions (and languages) # Please add more languages here (and add a few tests) - see CONTRIBUTING.md @@ -23,7 +23,8 @@ '.js': {'language': 'javascript', 'comment': '//'}, '.ts': {'language': 'typescript', 'comment': '//'}, '.scala': {'language': 'scala', 'comment': '//'}, - '.rs': {'language': 'rust', 'comment': '//'}} + '.rs': {'language': 'rust', 'comment': '//'}, + '.robot': {'language': 'robotframework', 'comment': '#'}} _COMMENT_CHARS = [_SCRIPT_EXTENSIONS[ext]['comment'] for ext in _SCRIPT_EXTENSIONS if _SCRIPT_EXTENSIONS[ext]['comment'] != '#'] diff --git a/tests/notebooks/ipynb_robot/simple_robot_notebook.ipynb b/tests/notebooks/ipynb_robot/simple_robot_notebook.ipynb new file mode 100644 index 000000000..7e9277628 --- /dev/null +++ b/tests/notebooks/ipynb_robot/simple_robot_notebook.ipynb @@ -0,0 +1,70 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "*** Settings ***\n", + "\n", + "Library Collections" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "*** Keywords ***\n", + "\n", + "Head\n", + " [Arguments] ${list}\n", + " ${value}= Get from list ${list} 0\n", + " [Return] ${value}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "lines_to_next_cell": 0 + }, + "outputs": [], + "source": [ + "*** Tasks ***\n", + "\n", + "Get head\n", + " ${array}= Create list 1 2 3 4 5\n", + " ${head}= Head ${array}\n", + " Should be equal ${head} 1" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Robot Framework", + "language": "robotframework", + "name": "robotkernel" + }, + "language_info": { + "codemirror_mode": "robotframework", + "file_extension": ".robot", + "mimetype": "text/plain", + "name": "robotframework", + "pygments_lexer": "robotframework" + }, + "pycharm": { + "stem_cell": { + "cell_type": "raw", + "source": [], + "metadata": { + "collapsed": false + } + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tests/test_mirror.py b/tests/test_mirror.py index d9e34d345..fa9a84e3f 100644 --- a/tests/test_mirror.py +++ b/tests/test_mirror.py @@ -248,3 +248,13 @@ def test_ipynb_to_scheme_percent(nb_file, extension, no_jupytext_version_number) assert_conversion_same_as_mirror(nb_file, '{}:percent'.format(extension), 'ipynb_to_percent') + + +@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_robot')) +def test_ipynb_to_robot_light(nb_file, no_jupytext_version_number): + assert_conversion_same_as_mirror(nb_file, 'auto', 'ipynb_to_script') + + +@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_robot')) +def test_ipynb_to_robot_percent(nb_file, no_jupytext_version_number): + assert_conversion_same_as_mirror(nb_file, 'auto:percent', 'ipynb_to_percent') From b418817506c46cb7619cf597360288b3b08106ae Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sat, 9 Nov 2019 09:53:19 +0100 Subject: [PATCH 2/6] Update the list of supported languages --- README.md | 2 +- docs/introduction.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 162b2c3f6..f40ee7915 100755 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ It can also convert these documents **into** Jupyter Notebooks, allowing you to synchronize content in both directions. -The languages that are currently supported by Jupytext are: Julia, Python, R, Bash, Scheme, Clojure, Matlab, Octave, C++, q/kdb+, IDL, TypeScript, Javascript, Scala, Rust/Evxcr and PowerShell. Extending Jupytext to more languages should be easy - read more at [CONTRIBUTING.md](https://github.com/mwouts/jupytext/blob/master/CONTRIBUTING.md). In addition, jupytext users can choose between two formats for notebooks as scripts: +The languages that are currently supported by Jupytext are: Julia, Python, R, Bash, Scheme, Clojure, Matlab, Octave, C++, q/kdb+, IDL, TypeScript, Javascript, Scala, Rust/Evxcr, PowerShell and Robot Framework. Extending Jupytext to more languages should be easy - read more at [CONTRIBUTING.md](https://github.com/mwouts/jupytext/blob/master/CONTRIBUTING.md). In addition, jupytext users can choose between two formats for notebooks as scripts: - The `percent` format, compatible with several IDEs, including Spyder, Hydrogen, VScode and PyCharm. In that format, cells are delimited with a commented `%%`. - The `light` format, designed for this project. Use that format to open standard scripts as notebooks, or to save notebooks as scripts with few cell markers - none when possible. diff --git a/docs/introduction.md b/docs/introduction.md index 3c4040d8a..1401dfac0 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -10,7 +10,7 @@ Jupytext can save Jupyter notebooks as - Markdown and R Markdown documents, - Scripts in many languages. -The languages that are currently supported by Jupytext are: Julia, Python, R, Bash, Scheme, Clojure, Matlab, Octave, C++, q/kdb+, IDL, TypeScript, Javascript and Scala. Extending Jupytext to more languages should be easy - read more at [CONTRIBUTING.md](https://github.com/mwouts/jupytext/blob/master/CONTRIBUTING.md#). In addition, jupytext users can choose between two formats for notebooks as scripts: +The languages that are currently supported by Jupytext are: Julia, Python, R, Bash, Scheme, Clojure, Matlab, Octave, C++, q/kdb+, IDL, TypeScript, Javascript, Scala, Rust/Evxcr, PowerShell and Robot Framework. Extending Jupytext to more languages should be easy - read more at [CONTRIBUTING.md](https://github.com/mwouts/jupytext/blob/master/CONTRIBUTING.md#). In addition, jupytext users can choose between two formats for notebooks as scripts: - The `percent` format, compatible with several IDEs, including Spyder, Hydrogen, VScode and PyCharm. In that format, cells are delimited with a commented `%%`. - The `light` format, designed for this project. Use that format to open standard scripts as notebooks, or to save notebooks as scripts with few cell markers - none when possible. From 7a75cf621e3532a194b96dd6108f54b04519ad48 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sat, 9 Nov 2019 10:01:38 +0100 Subject: [PATCH 3/6] Update CONTRIBUTING.md --- CONTRIBUTING.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 11b0ee366..9c105432f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,8 +28,7 @@ You want to submit an enhancement on Jupytext? Unless this is a small change, we A pull request for which you do not need to contact us in advance is the addition of a new language to Jupytext. In principle that should be easy - you would only have to: - document the language extension and comment by adding one line to `_SCRIPT_EXTENSIONS` in `languages.py`. - contribute a sample notebook in `tests/notebooks/ipynb_[language]`. -- add two tests in `test_mirror.py`: one for the `light` format, and another one for the `percent` format. -- Make sure that the tests pass, and that the text representations of your notebook, found in `tests/notebooks/mirror/ipynb_to_script` and `tests/notebooks/mirror/ipynb_to_percent`, are valid scripts. +- run the tests suite (with just `pytest`). The mirror tests will generate various text representations corresponding to your notebook under `tests/notebooks/mirror/`. Please verify that these files are valid scripts, and commit them. # How to setup a development environment for Jupytext From 2d929a449d708b84bf40df80e988af46cecb6ac8 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sat, 9 Nov 2019 10:02:00 +0100 Subject: [PATCH 4/6] Remove duplicate tests --- tests/test_mirror.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/test_mirror.py b/tests/test_mirror.py index fa9a84e3f..d9e34d345 100644 --- a/tests/test_mirror.py +++ b/tests/test_mirror.py @@ -248,13 +248,3 @@ def test_ipynb_to_scheme_percent(nb_file, extension, no_jupytext_version_number) assert_conversion_same_as_mirror(nb_file, '{}:percent'.format(extension), 'ipynb_to_percent') - - -@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_robot')) -def test_ipynb_to_robot_light(nb_file, no_jupytext_version_number): - assert_conversion_same_as_mirror(nb_file, 'auto', 'ipynb_to_script') - - -@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_robot')) -def test_ipynb_to_robot_percent(nb_file, no_jupytext_version_number): - assert_conversion_same_as_mirror(nb_file, 'auto:percent', 'ipynb_to_percent') From 2454a5875fa92741f54883c8efa78fde9094f317 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sat, 9 Nov 2019 10:02:41 +0100 Subject: [PATCH 5/6] Add the mirror representation of Robot Framework notebook --- .../ipynb_to_Rmd/simple_robot_notebook.Rmd | 31 +++++++++++++++++++ .../simple_robot_notebook.robot | 28 +++++++++++++++++ .../ipynb_to_md/simple_robot_notebook.md | 31 +++++++++++++++++++ .../simple_robot_notebook.robot | 28 +++++++++++++++++ .../simple_robot_notebook.robot | 28 +++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 tests/notebooks/mirror/ipynb_to_Rmd/simple_robot_notebook.Rmd create mode 100644 tests/notebooks/mirror/ipynb_to_hydrogen/simple_robot_notebook.robot create mode 100644 tests/notebooks/mirror/ipynb_to_md/simple_robot_notebook.md create mode 100644 tests/notebooks/mirror/ipynb_to_percent/simple_robot_notebook.robot create mode 100644 tests/notebooks/mirror/ipynb_to_script/simple_robot_notebook.robot diff --git a/tests/notebooks/mirror/ipynb_to_Rmd/simple_robot_notebook.Rmd b/tests/notebooks/mirror/ipynb_to_Rmd/simple_robot_notebook.Rmd new file mode 100644 index 000000000..2821c7caf --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_Rmd/simple_robot_notebook.Rmd @@ -0,0 +1,31 @@ +--- +jupyter: + kernelspec: + display_name: Robot Framework + language: robotframework + name: robotkernel +--- + +```{robotframework} +*** Settings *** + +Library Collections +``` + +```{robotframework} +*** Keywords *** + +Head + [Arguments] ${list} + ${value}= Get from list ${list} 0 + [Return] ${value} +``` + +```{robotframework} +*** Tasks *** + +Get head + ${array}= Create list 1 2 3 4 5 + ${head}= Head ${array} + Should be equal ${head} 1 +``` diff --git a/tests/notebooks/mirror/ipynb_to_hydrogen/simple_robot_notebook.robot b/tests/notebooks/mirror/ipynb_to_hydrogen/simple_robot_notebook.robot new file mode 100644 index 000000000..932a13341 --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_hydrogen/simple_robot_notebook.robot @@ -0,0 +1,28 @@ +# --- +# jupyter: +# kernelspec: +# display_name: Robot Framework +# language: robotframework +# name: robotkernel +# --- + +# %% +*** Settings *** + +Library Collections + +# %% +*** Keywords *** + +Head + [Arguments] ${list} + ${value}= Get from list ${list} 0 + [Return] ${value} + +# %% +*** Tasks *** + +Get head + ${array}= Create list 1 2 3 4 5 + ${head}= Head ${array} + Should be equal ${head} 1 diff --git a/tests/notebooks/mirror/ipynb_to_md/simple_robot_notebook.md b/tests/notebooks/mirror/ipynb_to_md/simple_robot_notebook.md new file mode 100644 index 000000000..7679d45bc --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_md/simple_robot_notebook.md @@ -0,0 +1,31 @@ +--- +jupyter: + kernelspec: + display_name: Robot Framework + language: robotframework + name: robotkernel +--- + +```robotframework +*** Settings *** + +Library Collections +``` + +```robotframework +*** Keywords *** + +Head + [Arguments] ${list} + ${value}= Get from list ${list} 0 + [Return] ${value} +``` + +```robotframework +*** Tasks *** + +Get head + ${array}= Create list 1 2 3 4 5 + ${head}= Head ${array} + Should be equal ${head} 1 +``` diff --git a/tests/notebooks/mirror/ipynb_to_percent/simple_robot_notebook.robot b/tests/notebooks/mirror/ipynb_to_percent/simple_robot_notebook.robot new file mode 100644 index 000000000..932a13341 --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_percent/simple_robot_notebook.robot @@ -0,0 +1,28 @@ +# --- +# jupyter: +# kernelspec: +# display_name: Robot Framework +# language: robotframework +# name: robotkernel +# --- + +# %% +*** Settings *** + +Library Collections + +# %% +*** Keywords *** + +Head + [Arguments] ${list} + ${value}= Get from list ${list} 0 + [Return] ${value} + +# %% +*** Tasks *** + +Get head + ${array}= Create list 1 2 3 4 5 + ${head}= Head ${array} + Should be equal ${head} 1 diff --git a/tests/notebooks/mirror/ipynb_to_script/simple_robot_notebook.robot b/tests/notebooks/mirror/ipynb_to_script/simple_robot_notebook.robot new file mode 100644 index 000000000..dfcf06b84 --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_script/simple_robot_notebook.robot @@ -0,0 +1,28 @@ +# --- +# jupyter: +# kernelspec: +# display_name: Robot Framework +# language: robotframework +# name: robotkernel +# --- + +# + +*** Settings *** + +Library Collections + +# + +*** Keywords *** + +Head + [Arguments] ${list} + ${value}= Get from list ${list} 0 + [Return] ${value} + +# + +*** Tasks *** + +Get head + ${array}= Create list 1 2 3 4 5 + ${head}= Head ${array} + Should be equal ${head} 1 From cae75da62a7837d9664796b94d789f4dfca7f0bf Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sat, 9 Nov 2019 10:04:42 +0100 Subject: [PATCH 6/6] Update HISTORY.rst --- HISTORY.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.rst b/HISTORY.rst index 79684e2ad..52edf6866 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -25,6 +25,7 @@ Release History - ``jupytext --check pytest notebook.ipynb`` can be used to run test functions in a notebook (#286) - ``jupytext --check`` and ``jupytext --pipe`` can run commands that only operate on files: when ``{}`` is found in the text of the command, ``jupytext`` saves the text representation of the notebook in a temp file, and replaces ``{}`` with the name of that file before executing the command. (#286) - Added support for Rust/Evxcr, by Jonas Bushart (#351) +- Added support for Robot Framework, by Akso Soukka (#378) - Added support for PowerShell (#349) **BugFixes**