Skip to content

Commit

Permalink
chmod +x required on linux #121
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Nov 27, 2018
1 parent 057f36a commit d032744
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
19 changes: 10 additions & 9 deletions jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] +
Expand All @@ -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. '
Expand Down
13 changes: 11 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import stat
from shutil import copyfile
import pytest
from testfixtures import compare
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d032744

Please sign in to comment.