Skip to content

Commit

Permalink
Comment indented bash commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Feb 16, 2020
1 parent 7fd991f commit 3f857d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion jupytext/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 21 additions & 0 deletions tests/test_read_simple_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 3f857d5

Please sign in to comment.