diff --git a/CHANGELOG.md b/CHANGELOG.md index e32545958..90ac8aa35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ **Fixed** - `jupytext --to script *.ipynb` now computes the script extension for each notebook (#428) - Fix shebang handling for languages with non-# comments, by Jonas Bushart (#434) +- Indented bash commands are now commented out (#437) 1.3.3 (2020-01-27) diff --git a/jupytext/magics.py b/jupytext/magics.py index 4fc352778..2b49064b2 100644 --- a/jupytext/magics.py +++ b/jupytext/magics.py @@ -26,7 +26,7 @@ _MAGIC_FORCE_ESC_RE['csharp'] = re.compile(r"^(// |//)*#![a-zA-Z](.*)//\s*noescape") # Commands starting with a question or exclamation mark have to be escaped -_PYTHON_HELP_OR_BASH_CMD = re.compile(r"^(# |#)*(\?|!)\s*[A-Za-z]") +_PYTHON_HELP_OR_BASH_CMD = re.compile(r"^(# |#)*\s*(\?|!)\s*[A-Za-z]") # A bash command not followed by an equal sign or a parenthesis is a magic command _PYTHON_MAGIC_CMD = re.compile(r"^(# |#)*({})($|\s$|\s[^=,])".format('|'.join( diff --git a/tests/test_read_simple_python.py b/tests/test_read_simple_python.py index 63417efcc..fd03a8ae9 100644 --- a/tests/test_read_simple_python.py +++ b/tests/test_read_simple_python.py @@ -935,3 +935,24 @@ def test_active_tag( compare_notebooks(nb, ref) py = jupytext.writes(nb, 'py') compare(py, text) + + +def test_indented_bash_command(no_jupytext_version_number, + nb=new_notebook(cells=[new_code_cell("""try: + !echo jo + pass +except: + pass""")]), + text="""try: +# !echo jo + pass +except: + pass +""" + + ): + """Reproduces https://github.com/mwouts/jupytext/issues/437""" + py = jupytext.writes(nb, 'py') + compare(py, text) + nb2 = jupytext.reads(py, 'py') + compare_notebooks(nb2, nb)