Skip to content

Commit

Permalink
Choices for command line to and from options are automatic #61
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Sep 27, 2018
1 parent e33a91a commit 498d59e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 8 additions & 8 deletions jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
check_file_version, one_format_as_string, parse_one_format
from .combine import combine_inputs_with_outputs
from .compare import test_round_trip_conversion
from .languages import _SCRIPT_EXTENSIONS


def convert_notebook_files(nb_files, fmt, input_format=None, output=None,
Expand Down Expand Up @@ -117,12 +118,11 @@ def canonize_format(format_or_ext, file_path=None):

raise ValueError('Please specificy either --to or --output')

return {'notebook': 'ipynb',
'python': 'py',
'julia': 'jl',
'r': 'R',
'markdown': 'md',
'rmarkdown': 'Rmd'}[format_or_ext]
for ext in _SCRIPT_EXTENSIONS:
if _SCRIPT_EXTENSIONS[ext]['language'] == format_or_ext:
return ext.replace('.', '')

return {'notebook': 'ipynb', 'markdown': 'md', 'rmarkdown': 'Rmd'}[format_or_ext]


def cli_jupytext(args=None):
Expand All @@ -131,8 +131,8 @@ def cli_jupytext(args=None):
description='Jupyter notebooks as markdown documents, '
'Julia, Python or R scripts')

notebook_formats = (['notebook', 'python', 'julia', 'r', 'markdown',
'rmarkdown'] +
notebook_formats = (['notebook', 'rmarkdown', 'markdown'] +
[_SCRIPT_EXTENSIONS[ext]['language'] for ext in _SCRIPT_EXTENSIONS] +
[ext.replace('.', '') for ext in NOTEBOOK_EXTENSIONS] +
[one_format_as_string(fmt.extension, fmt.format_name)
for fmt in JUPYTEXT_FORMATS])
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ def test_convert_single_file(nb_file, capsys):
compare(out, pynb)


@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_cpp'))
def test_to_cpluplus(nb_file, capsys):
nb1 = readf(nb_file)
text_cpp = writes(nb1, ext='.cpp')
jupytext([nb_file, '--to', 'c++', '--output', '-'])

out, err = capsys.readouterr()
assert err == ''
compare(out, text_cpp)


@pytest.mark.parametrize('nb_files', [list_notebooks('ipynb_py')])
def test_convert_multiple_file(nb_files, tmpdir):
nb_orgs = []
Expand Down

0 comments on commit 498d59e

Please sign in to comment.