From 0ab6000d27ce2cbab189c797e0c7931f87d6c138 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Fri, 29 Mar 2019 07:33:01 +0100 Subject: [PATCH] Skip pandoc format and tests when pandoc>=2.7.1 is not available #208 --- jupytext/formats.py | 14 ++++---------- jupytext/pandoc.py | 9 +++++++++ tests/test_mirror.py | 3 ++- tests/test_read_simple_pandoc.py | 3 +++ tests/utils.py | 2 ++ 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/jupytext/formats.py b/jupytext/formats.py index 3931cf56b..7f67f9545 100644 --- a/jupytext/formats.py +++ b/jupytext/formats.py @@ -16,7 +16,7 @@ from .metadata_filter import metadata_filter_as_string from .stringparser import StringParser from .languages import _SCRIPT_EXTENSIONS, _COMMENT_CHARS -from .pandoc import pandoc_version +from .pandoc import pandoc_version, is_pandoc_available class JupytextFormatError(ValueError): @@ -135,20 +135,14 @@ def __init__(self, current_version_number='1.1') ] - -def pandoc_format(): - """Jupytext's format description for Pandoc's Markdown""" - - return NotebookFormatDescription( +if is_pandoc_available(): + JUPYTEXT_FORMATS.append(NotebookFormatDescription( format_name='pandoc', extension='.md', header_prefix='', cell_reader_class=None, cell_exporter_class=None, - current_version_number=pandoc_version()) - - -JUPYTEXT_FORMATS.append(pandoc_format()) + current_version_number=pandoc_version())) NOTEBOOK_EXTENSIONS = list(dict.fromkeys(['.ipynb'] + [fmt.extension for fmt in JUPYTEXT_FORMATS])) EXTENSION_PREFIXES = ['.lgt', '.spx', '.pct', '.hyd', '.nb'] diff --git a/jupytext/pandoc.py b/jupytext/pandoc.py index bc04b7b30..8c89dbad3 100644 --- a/jupytext/pandoc.py +++ b/jupytext/pandoc.py @@ -32,6 +32,15 @@ def pandoc(args, filein=None, fileout=None): return out.decode('utf-8') +def is_pandoc_available(): + """Is Pandoc>=2.7.1 available?""" + try: + pandoc_version() + return True + except (IOError, PandocError): + return False + + def pandoc_version(): """Pandoc's version number""" version = pandoc(u'--version').splitlines()[0].split()[1] diff --git a/tests/test_mirror.py b/tests/test_mirror.py index 734a6a2a7..6e21019c6 100644 --- a/tests/test_mirror.py +++ b/tests/test_mirror.py @@ -12,7 +12,7 @@ from jupytext.compare import compare_notebooks, combine_inputs_with_outputs from jupytext.formats import long_form_one_format from jupytext.paired_paths import full_path -from .utils import list_notebooks, skip_if_dict_is_not_ordered +from .utils import list_notebooks, skip_if_dict_is_not_ordered, requires_pandoc pytestmark = skip_if_dict_is_not_ordered @@ -261,6 +261,7 @@ def test_ipynb_to_md(nb_file): assert_conversion_same_as_mirror(nb_file, 'md', 'ipynb_to_md') +@requires_pandoc @pytest.mark.parametrize('nb_file', list_notebooks('ipynb')) def test_ipynb_to_pandoc(nb_file): assert_conversion_same_as_mirror(nb_file, 'md:pandoc', 'ipynb_to_pandoc') diff --git a/tests/test_read_simple_pandoc.py b/tests/test_read_simple_pandoc.py index 3bd5a517c..e0caa3b62 100644 --- a/tests/test_read_simple_pandoc.py +++ b/tests/test_read_simple_pandoc.py @@ -1,8 +1,10 @@ from testfixtures import compare from jupytext.compare import compare_notebooks import jupytext +from .utils import requires_pandoc +@requires_pandoc def test_pandoc_implicit(markdown='''# Lorem ipsum **Lorem ipsum** dolor sit amet, consectetur adipiscing elit. Nunc luctus @@ -22,6 +24,7 @@ def test_pandoc_implicit(markdown='''# Lorem ipsum compare(markdown2, markdown3) +@requires_pandoc def test_pandoc_explicit(markdown='''::: {.cell .markdown} # Lorem diff --git a/tests/utils.py b/tests/utils.py index c5561cc5f..a8e4c2572 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -4,6 +4,7 @@ import pytest from jupytext.cli import system from jupytext.cell_reader import rst2md +from jupytext.pandoc import is_pandoc_available skip_if_dict_is_not_ordered = pytest.mark.skipif( sys.version_info < (3, 6), @@ -21,6 +22,7 @@ def tool_version(tool): requires_flake8 = pytest.mark.skipif(not tool_version('flake8'), reason='flake8 not found') requires_autopep8 = pytest.mark.skipif(not tool_version('autopep8'), reason='autopep8 not found') requires_sphinx_gallery = pytest.mark.skipif(not rst2md, reason='sphinx_gallery not available') +requires_pandoc = pytest.mark.skipif(not is_pandoc_available(), reason='pandoc>=2.7.1 not available') def list_notebooks(path='ipynb', skip='World'):