How to use the jupytext.formats.guess_format function in jupytext

To help you get started, we’ve selected a few jupytext examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mwouts / jupytext / tests / test_formats.py View on Github external
def test_script_with_spyder_cell_with_name_is_percent(script="""#%% cell name
1 + 2"""):
    assert guess_format(script, '.py')[0] == 'percent'
github mwouts / jupytext / tests / test_formats.py View on Github external
def test_script_with_spyder_cell_is_percent(script="""#%%
1 + 2"""):
    assert guess_format(script, '.py')[0] == 'percent'
github mwouts / jupytext / tests / test_formats.py View on Github external
def test_guess_format_hydrogen():
    text = """# %%
cat hello.txt
"""
    assert guess_format(text, ext='.py')[0] == 'hydrogen'
github mwouts / jupytext / tests / test_read_simple_percent.py View on Github external
# Again, a markdown cell

# In[33]:


2 + 2


# 


3 + 3
"""):
    assert jupytext.formats.guess_format(script, '.py')[0] == 'percent'
    nb = jupytext.reads(script, '.py')
    assert len(nb.cells) == 5
github mwouts / jupytext / tests / test_read_simple_hydrogen.py View on Github external
# Again, a markdown cell

# In[33]:


2 + 2


# 


3 + 3
"""):
    assert jupytext.formats.guess_format(script, '.py')[0] == 'hydrogen'
    nb = jupytext.reads(script, '.py')
    assert len(nb.cells) == 5
github mwouts / jupytext / tests / test_formats.py View on Github external
def test_guess_format_percent(nb_file):
    with open(nb_file) as stream:
        assert guess_format(stream.read(), ext='.py')[0] == 'percent'
github mwouts / jupytext / tests / test_formats.py View on Github external
def test_guess_format_sphinx(nb_file):
    with open(nb_file) as stream:
        assert guess_format(stream.read(), ext='.py')[0] == 'sphinx'
github mwouts / jupytext / tests / test_formats.py View on Github external
def test_guess_format_light(nb_file):
    with open(nb_file) as stream:
        assert guess_format(stream.read(), ext='.py')[0] == 'light'
github mwouts / jupytext / jupytext / jupytext.py View on Github external
:param kwargs: (not used) additional parameters for nbformat.reads
    :return: the notebook
    """
    fmt = copy(fmt) if fmt else divine_format(text)
    fmt = long_form_one_format(fmt)
    ext = fmt['extension']

    if ext == '.ipynb':
        return nbformat.reads(text, as_version, **kwargs)

    format_name = read_format_from_metadata(text, ext) or fmt.get('format_name')

    if format_name:
        format_options = {}
    else:
        format_name, format_options = guess_format(text, ext)

    if format_name:
        fmt['format_name'] = format_name

    fmt.update(format_options)
    reader = TextNotebookConverter(fmt)
    notebook = reader.reads(text, **kwargs)
    rearrange_jupytext_metadata(notebook.metadata)

    if format_name and insert_or_test_version_number():
        notebook.metadata.setdefault('jupytext', {}).setdefault('text_representation', {}).update(
            {'extension': ext, 'format_name': format_name})

    return notebook