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

Comment indented bash commands #439

Merged
merged 1 commit into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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)