Skip to content

Commit

Permalink
version argument in command line jupytext #103
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Oct 18, 2018
1 parent b87f646 commit 1abde87
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .combine import combine_inputs_with_outputs
from .compare import test_round_trip_conversion, NotebookDifference
from .languages import _SCRIPT_EXTENSIONS
from .version import __version__


def convert_notebook_files(nb_files, fmt, input_format=None, output=None,
Expand Down Expand Up @@ -170,8 +171,13 @@ def cli_jupytext(args=None):
'round trip conversion')
parser.add_argument('-x', '--stop', dest='stop_on_first_error', action='store_true',
help='Stop on first round trip conversion error, and report stack traceback')
parser.add_argument('--version', action='store_true',
help="Show jupytext's version number and exit")
args = parser.parse_args(args)

if args.version:
return args

args.to = canonize_format(args.to, args.output)

if args.input_format:
Expand All @@ -193,6 +199,11 @@ def jupytext(args=None):
"""Entry point for the jupytext script"""
try:
args = cli_jupytext(args)

if args.version:
sys.stdout.write(__version__)
return

convert_notebook_files(nb_files=args.notebooks,
fmt=args.to,
input_format=args.input_format,
Expand Down
10 changes: 9 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from testfixtures import compare
import mock
from nbformat.v4.nbbase import new_notebook
from jupytext import header
from jupytext import header, __version__
from jupytext import readf, writef, writes
from jupytext.cli import convert_notebook_files, cli_jupytext, jupytext
from jupytext.compare import compare_notebooks
Expand Down Expand Up @@ -55,6 +55,14 @@ def test_convert_single_file(nb_file, capsys):
compare(out, pynb)


def test_jupytext_version(capsys):
jupytext(['--version'])

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


@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_cpp'))
def test_to_cpluplus(nb_file, capsys):
nb1 = readf(nb_file)
Expand Down

0 comments on commit 1abde87

Please sign in to comment.