diff --git a/jupytext/cli.py b/jupytext/cli.py index 6ed644f63..01c7395a9 100644 --- a/jupytext/cli.py +++ b/jupytext/cli.py @@ -201,8 +201,8 @@ def str2bool(input): def cli_jupytext(args=None): """Command line parser for jupytext""" parser = argparse.ArgumentParser( - description='Jupyter notebooks as markdown documents, ' - 'Julia, Python or R scripts') + description='Jupyter notebooks as markdown documents, Julia, Python or R scripts', + formatter_class=argparse.RawTextHelpFormatter) notebook_formats = (['notebook', 'rmarkdown', 'markdown'] + [_SCRIPT_EXTENSIONS[ext]['language'] for ext in _SCRIPT_EXTENSIONS] + @@ -218,15 +218,16 @@ def cli_jupytext(args=None): choices=notebook_formats, help="Input format") parser.add_argument('notebooks', - help='One or more notebook(s) to be converted. Input ' - 'is read from stdin when no notebook is ' - 'provided , but then the --from field is ' - 'mandatory', + help='One or more notebook(s). Input is read from stdin when no notebook ' + 'is provided , but then the --from field is mandatory', nargs='*') parser.add_argument('--pre-commit', action='store_true', - help="""Run Jupytext on the ipynb files in the git index. Use Jupytext - as a pre-commit hook with: echo '#!/bin/sh - jupytext --to py:light --pre-commit' > .git/hooks/pre-commit""") + help="""Run Jupytext on the ipynb files in the git index. +Create a pre-commit hook with: + +echo '#!/bin/sh +jupytext --to py:light --pre-commit' > .git/hooks/pre-commit +chmod +x .git/hooks/pre-commit""") parser.add_argument('-o', '--output', help='Destination file. Defaults to original file, ' 'with extension changed to destination format. ' diff --git a/tests/test_cli.py b/tests/test_cli.py index d2759e0fa..1d94a8d4e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,4 +1,5 @@ import os +import stat from shutil import copyfile import pytest from testfixtures import compare @@ -256,10 +257,14 @@ def git(*args): git('init') git('status') - with open(str(tmpdir.join('.git/hooks/pre-commit')), 'w') as fp: + hook = str(tmpdir.join('.git/hooks/pre-commit')) + with open(hook, 'w') as fp: fp.write('#!/bin/sh\n' 'jupytext --to py:light --pre-commit\n') + st = os.stat(hook) + os.chmod(hook, st.st_mode | stat.S_IEXEC) + writef(nb, tmp_ipynb) assert os.path.isfile(tmp_ipynb) assert not os.path.isfile(tmp_py) @@ -291,11 +296,15 @@ def git(*args): git('init') git('status') - with open(str(tmpdir.join('.git/hooks/pre-commit')), 'w') as fp: + hook = str(tmpdir.join('.git/hooks/pre-commit')) + with open(hook, 'w') as fp: fp.write('#!/bin/sh\n' 'jupytext --from py:light --to ipynb --pre-commit\n' 'jupytext --from py:light --to md --pre-commit\n') + st = os.stat(hook) + os.chmod(hook, st.st_mode | stat.S_IEXEC) + writef(nb, tmp_py) assert os.path.isfile(tmp_py) assert not os.path.isfile(tmp_ipynb)