Skip to content

Commit

Permalink
Allow spaces between ? or ! and python or bash command
Browse files Browse the repository at this point in the history
Fixes #189
  • Loading branch information
mwouts committed Feb 26, 2019
1 parent f870d91 commit 931053c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Release History
---------------

1.0.2 (2019-02-??)
++++++++++++++++++++++

**BugFixes**
- Allow spaces between ``?`` or ``!`` and python or bash command (#189)


1.0.1 (2019-02-23)
++++++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion jupytext/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
_COMMENT = {_SCRIPT_EXTENSIONS[ext]['language']: _SCRIPT_EXTENSIONS[ext]['comment'] for ext in _SCRIPT_EXTENSIONS}

# Commands starting with a question or exclamation mark have to be escaped
_PYTHON_HELP_OR_BASH_CMD = re.compile(r"^(# |#)*(\?|!)[A-Za-z]")
_PYTHON_HELP_OR_BASH_CMD = re.compile(r"^(# |#)*(\?|!)\s*[A-Za-z]")

_PYTHON_MAGIC_CMD = re.compile(r"^(# |#)*({})(\s|$)".format('|'.join(
# posix
Expand Down
14 changes: 7 additions & 7 deletions tests/test_escape_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,22 @@ def test_force_comment_using_contents_manager(tmpdir):
assert '%pylab inline' in stream.read().splitlines()


@pytest.mark.parametrize('magic_cmd', ['ls', '!ls', 'ls -al', '!whoami', '# ls', '# mv a b'])
@pytest.mark.parametrize('magic_cmd', ['ls', '!ls', 'ls -al', '!whoami', '# ls', '# mv a b', '! mkdir tmp'])
def test_comment_bash_commands_in_python(magic_cmd):
comment_magic([magic_cmd]) == ['# ' + magic_cmd]
uncomment_magic(['# ' + magic_cmd]) == magic_cmd
assert comment_magic([magic_cmd]) == ['# ' + magic_cmd]
assert uncomment_magic(['# ' + magic_cmd]) == [magic_cmd]


@pytest.mark.parametrize('not_magic_cmd', ['copy(a)', 'copy.deepcopy'])
def test_do_not_comment_python_cmds(not_magic_cmd):
comment_magic([not_magic_cmd]) == [not_magic_cmd]
uncomment_magic([not_magic_cmd]) == not_magic_cmd
assert comment_magic([not_magic_cmd]) == [not_magic_cmd]
assert uncomment_magic([not_magic_cmd]) == [not_magic_cmd]


@pytest.mark.parametrize('magic_cmd', ['ls', '!ls', 'ls -al', '!whoami', '# ls', '# mv a b'])
def test_do_not_comment_bash_commands_in_R(magic_cmd):
comment_magic([magic_cmd], language='R') == ['# ' + magic_cmd]
uncomment_magic(['# ' + magic_cmd], language='R') == magic_cmd
assert comment_magic([magic_cmd], language='R') == [magic_cmd]
assert uncomment_magic([magic_cmd], language='R') == [magic_cmd]


def test_markdown_image_is_not_magic():
Expand Down

0 comments on commit 931053c

Please sign in to comment.