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

Empty MyST files fail to open as notebooks (IndexError: list index out of range) #883

Closed
mwouts opened this issue Dec 2, 2021 · 0 comments · Fixed by #884
Closed

Empty MyST files fail to open as notebooks (IndexError: list index out of range) #883

mwouts opened this issue Dec 2, 2021 · 0 comments · Fixed by #884

Comments

@mwouts
Copy link
Owner

mwouts commented Dec 2, 2021

This can be seen with the test test_read_empty_text_notebook at https://github.com/mwouts/jupytext/tree/test_read_empty_text_notebook

The error is the following:

tests/test_read_empty_text_notebook.py:8 (test_read_empty_text_notebook[.mnb])
ext = '.mnb'
tmp_path = PosixPath('/tmp/pytest-of-marc/pytest-6/test_read_empty_text_notebook_34')

    @pytest.mark.parametrize('ext', set(NOTEBOOK_EXTENSIONS)-{'.ipynb'})
    def test_read_empty_text_notebook(ext, tmp_path):
        if ext == '.qmd' and not is_quarto_available(min_version="0.2.0"):
            pytest.skip("quarto is not available")
        if ext in myst_extensions(no_md=True) and not is_myst_available():
            pytest.skip('MyST is not available')
    
        empty_nb = (tmp_path / "notebook").with_suffix(ext)
        empty_nb.touch()
    
>       nb = jupytext.read(empty_nb)

tests/test_read_empty_text_notebook.py:19: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jupytext/jupytext.py:409: in read
    return read(stream, as_version=as_version, fmt=fmt, config=config, **kwargs)
jupytext/jupytext.py:418: in read
    return reads(fp.read(), fmt, config=config, **kwargs)
jupytext/jupytext.py:370: in reads
    notebook = reader.reads(text, **kwargs)
jupytext/jupytext.py:104: in reads
    return myst_to_notebook(s)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

text = '', code_directive = '{code-cell}', raw_directive = '{raw-cell}'
add_source_map = False

    def myst_to_notebook(
        text,
        code_directive=CODE_DIRECTIVE,
        raw_directive=RAW_DIRECTIVE,
        add_source_map=False,
    ):
        """Convert text written in the myst format to a notebook.
    
        :param text: the file text
        :param code_directive: the name of the directive to search for containing code cells
        :param raw_directive: the name of the directive to search for containing raw cells
        :param add_source_map: add a `source_map` key to the notebook metadata,
            which is a list of the starting source line number for each cell.
    
        :raises MystMetadataParsingError if the metadata block is not valid JSON/YAML
    
        NOTE: we assume here that all of these directives are at the top-level,
        i.e. not nested in other directives.
        """
        raise_if_myst_is_not_available()
    
        tokens = get_parser().parse(text + "\n")
        lines = text.splitlines()
        md_start_line = 0
    
        # get the document metadata
        metadata_nb = {}
>       if tokens[0].type == "front_matter":
E       IndexError: list index out of range

jupytext/myst.py:286: IndexError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant