Skip to content

Commit

Permalink
Skip pandoc format and tests when pandoc>=2.7.1 is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Mar 29, 2019
1 parent 4df6429 commit 0ab6000
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
14 changes: 4 additions & 10 deletions jupytext/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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']
Expand Down
9 changes: 9 additions & 0 deletions jupytext/pandoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion tests/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')
3 changes: 3 additions & 0 deletions tests/test_read_simple_pandoc.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,6 +24,7 @@ def test_pandoc_implicit(markdown='''# Lorem ipsum
compare(markdown2, markdown3)


@requires_pandoc
def test_pandoc_explicit(markdown='''::: {.cell .markdown}
# Lorem
Expand Down
2 changes: 2 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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'):
Expand Down

0 comments on commit 0ab6000

Please sign in to comment.