Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __main__ to allow calling via python -m #739

Merged
merged 2 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions jupytext/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
""" Main for Jupytext

Call with (e.g.)::

python -m jupytext my_notebook.ipynb --to Rmd
"""

import sys

from .cli import jupytext

if __name__ == "__main__":
sys.exit(jupytext())
19 changes: 19 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from argparse import ArgumentTypeError
from io import StringIO
from shutil import copyfile
from subprocess import check_call

import nbformat
import pytest
Expand Down Expand Up @@ -65,6 +66,24 @@ def test_convert_single_file_in_place(nb_file, tmpdir):
compare_notebooks(nb2, nb1)


def test_convert_single_file_in_place_m(tmpdir):
nb_file = list_notebooks("ipynb_py")[0]
nb_org = str(tmpdir.join(os.path.basename(nb_file)))
copyfile(nb_file, nb_org)

base, ext = os.path.splitext(nb_org)

for fmt_ext in ("py", "Rmd"):
nb_other = base + "." + fmt_ext

check_call([sys.executable, "-m", "jupytext", nb_org, "--to", fmt_ext])

nb1 = read(nb_org)
nb2 = read(nb_other)

compare_notebooks(nb2, nb1)


@pytest.mark.parametrize("nb_file", list_notebooks("ipynb") + list_notebooks("Rmd"))
def test_convert_single_file(nb_file, tmpdir, capsys):
nb_org = str(tmpdir.join(os.path.basename(nb_file)))
Expand Down