From 1abde87be8692086973546822d2d802de6c07c10 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Thu, 18 Oct 2018 23:46:07 +0200 Subject: [PATCH] version argument in command line jupytext #103 --- jupytext/cli.py | 11 +++++++++++ tests/test_cli.py | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/jupytext/cli.py b/jupytext/cli.py index a1555c3dd..8fc2ce2a8 100644 --- a/jupytext/cli.py +++ b/jupytext/cli.py @@ -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, @@ -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: @@ -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, diff --git a/tests/test_cli.py b/tests/test_cli.py index 7809260db..c07d5bb12 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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 @@ -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)