当前位置: 首页>>代码示例>>Python>>正文


Python preprocessors.ExecutePreprocessor方法代码示例

本文整理汇总了Python中nbconvert.preprocessors.ExecutePreprocessor方法的典型用法代码示例。如果您正苦于以下问题:Python preprocessors.ExecutePreprocessor方法的具体用法?Python preprocessors.ExecutePreprocessor怎么用?Python preprocessors.ExecutePreprocessor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nbconvert.preprocessors的用法示例。


在下文中一共展示了preprocessors.ExecutePreprocessor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_timeseries_controls

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def test_timeseries_controls(self):
        nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME)
        abs_path = Path(_NB_FOLDER).absolute()
        with open(nb_path) as f:
            nb = nbformat.read(f, as_version=4)
        ep = ExecutePreprocessor(timeout=600, kernel_name="python3")

        try:
            ep.preprocess(nb, {"metadata": {"path": abs_path}})
        except CellExecutionError:
            nb_err = str(nb_path).replace(".ipynb", "-err.ipynb")
            msg = f"Error executing the notebook '{nb_path}'.\n"
            msg += f"See notebook '{nb_err}' for the traceback."
            print(msg)
            with open(nb_err, mode="w", encoding="utf-8") as f:
                nbformat.write(nb, f)
            raise 
开发者ID:microsoft,项目名称:msticpy,代码行数:19,代码来源:test_timeseries.py

示例2: run_notebook

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def run_notebook(notebook_path):
    nb_name, _ = os.path.splitext(os.path.basename(notebook_path))

    with open(notebook_path) as f:
        nb = nbformat.read(f, as_version=4)

    proc = ExecutePreprocessor(timeout=600, kernel_name='python3')
    proc.allow_errors = True
    proc.preprocess(nb)

    for num, cell in enumerate(nb.cells):
        if 'outputs' in cell:
            for output in cell['outputs']:
                if output.output_type == 'error':
                    return cell.execution_count, output.traceback

    return None

# 7-bit C1 ANSI sequences 
开发者ID:pmelchior,项目名称:scarlet,代码行数:21,代码来源:test_docs.py

示例3: run_notebook

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def run_notebook(path, workdir=None, timeout=_DEFAULT_TIMEOUT):
    resources = {
        'metadata': {
            'path': workdir
        }
    } if workdir is not None else None

    with open(path, 'r') as f:
        nb = nbformat.read(f, as_version=_DEFAULT_IPYNB_VERSION)
    ep = ExecutePreprocessor(timeout=timeout)

    # Some notebooks may generate and automatically open reports in a web browser.
    # This is inconvenient in an automated test suite, so let's disable it.
    # Overwriting $BROWSER with a dummy command will keep the notebook
    # kernel from being able to open a web browser on Linux.
    # TODO find platform-neutral solution to suppress webbrowser.open
    browser = os.environ.get('BROWSER', None)
    os.environ['BROWSER'] = 'echo %s'
    ep.preprocess(nb, resources=resources)
    os.environ['BROWSER'] = browser 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:22,代码来源:notebookstestcase.py

示例4: test_clustering_nbdisplay_notebook

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def test_clustering_nbdisplay_notebook(self):
        nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME)
        abs_path = Path(_NB_FOLDER).absolute()
        with open(nb_path) as f:
            nb = nbformat.read(f, as_version=4)
        ep = ExecutePreprocessor(timeout=600, kernel_name="python3")

        try:
            ep.preprocess(nb, {"metadata": {"path": abs_path}})
        except CellExecutionError:
            nb_err = str(nb_path).replace(".ipynb", "-err.ipynb")
            msg = f"Error executing the notebook '{nb_path}'.\n"
            msg += f"See notebook '{nb_err}' for the traceback."
            print(msg)
            with open(nb_err, mode="w", encoding="utf-8") as f:
                nbformat.write(nb, f)
            raise 
开发者ID:microsoft,项目名称:msticpy,代码行数:19,代码来源:test_nbdisplay.py

示例5: test_process_tree_notebook

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def test_process_tree_notebook():
    nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME)
    abs_path = Path(_NB_FOLDER).absolute()
    with open(nb_path) as f:
        nb = nbformat.read(f, as_version=4)
    ep = ExecutePreprocessor(timeout=600, kernel_name="python3")

    try:
        ep.preprocess(nb, {"metadata": {"path": abs_path}})
    except CellExecutionError:
        nb_err = str(nb_path).replace(".ipynb", "-err.ipynb")
        msg = f"Error executing the notebook '{nb_path}'.\n"
        msg += f"See notebook '{nb_err}' for the traceback."
        print(msg)
        with open(nb_err, mode="w", encoding="utf-8") as f:
            nbformat.write(nb, f)
        raise 
开发者ID:microsoft,项目名称:msticpy,代码行数:19,代码来源:test_process_tree_utils.py

示例6: test_geoip_notebook

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def test_geoip_notebook(self):
        nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME)
        abs_path = Path(_NB_FOLDER).absolute()

        with open(nb_path, "rb") as f:
            nb_bytes = f.read()
        nb_text = nb_bytes.decode("utf-8")
        nb = nbformat.reads(nb_text, as_version=4)
        ep = ExecutePreprocessor(timeout=600, kernel_name="python3")

        try:
            ep.preprocess(nb, {"metadata": {"path": abs_path}})
        except CellExecutionError:
            nb_err = str(nb_path).replace(".ipynb", "-err.ipynb")
            msg = f"Error executing the notebook '{nb_path}'.\n"
            msg += f"See notebook '{nb_err}' for the traceback."
            print(msg)
            with open(nb_err, mode="w", encoding="utf-8") as f:
                nbformat.write(nb, f)
            raise 
开发者ID:microsoft,项目名称:msticpy,代码行数:22,代码来源:test_geoip.py

示例7: test_timeline_controls

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def test_timeline_controls(self):
        nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME)
        abs_path = Path(_NB_FOLDER).absolute()
        with open(nb_path) as f:
            nb = nbformat.read(f, as_version=4)
        ep = ExecutePreprocessor(timeout=600, kernel_name="python3")

        try:
            ep.preprocess(nb, {"metadata": {"path": abs_path}})
        except CellExecutionError:
            nb_err = str(nb_path).replace(".ipynb", "-err.ipynb")
            msg = f"Error executing the notebook '{nb_path}'.\n"
            msg += f"See notebook '{nb_err}' for the traceback."
            print(msg)
            with open(nb_err, mode="w", encoding="utf-8") as f:
                nbformat.write(nb, f)
            raise 
开发者ID:microsoft,项目名称:msticpy,代码行数:19,代码来源:test_timeline.py

示例8: test_widgets_notebook

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def test_widgets_notebook(self):
        nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME)
        abs_path = Path(_NB_FOLDER).absolute()
        with open(nb_path) as f:
            nb = nbformat.read(f, as_version=4)
        ep = ExecutePreprocessor(timeout=600, kernel_name="python3")

        try:
            ep.preprocess(nb, {"metadata": {"path": abs_path}})
        except CellExecutionError:
            nb_err = str(nb_path).replace(".ipynb", "-err.ipynb")
            msg = f"Error executing the notebook '{nb_path}'.\n"
            msg += f"See notebook '{nb_err}' for the traceback."
            print(msg)
            with open(nb_err, mode="w", encoding="utf-8") as f:
                nbformat.write(nb, f)
            raise 
开发者ID:microsoft,项目名称:msticpy,代码行数:19,代码来源:test_nbwidgets.py

示例9: metadata_notebook

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def metadata_notebook(tmpdir, request):
    nb = nbformat.v4.new_notebook()

    ep = ExecutePreprocessor()
    ep.preprocess(nb, {'metadata': {'path': tmpdir}})

    nb['metadata'].update(
        {
            'authors': [{'name': 'author1'}, {'name': 'author2'}],
            'subtitle': 'subtitle',
            'date': '2019-05-11',
            'path': f'{tmpdir}',
        }
    )
    if request.param:
        nb['metadata']['title'] = 'title'

    return nb 
开发者ID:m-rossi,项目名称:jupyter-docx-bundler,代码行数:20,代码来源:conftest.py

示例10: run_notebook

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def run_notebook(filename):

    run_path = os.path.split(filename)[0]

    with open(filename) as f:
        nb = nbformat.read(f, as_version=4)

    try:
        ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
        ep.preprocess(nb, {'metadata': {'path': run_path}})

        # FIXME: use tempfile and mv to avoid interruption
        # better split the source code of the notebook and the compiled targets.
        with open(filename, 'wt') as f:
            nbformat.write(nb, f)

    except Exception as e:
        print('processing', filename, e) 
开发者ID:bccp,项目名称:nbodykit,代码行数:20,代码来源:run_notebooks.py

示例11: convert

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def convert(nbfile):
    basename, _ = os.path.splitext(nbfile)

    meta = {'metadata': {'path': '.'}}
    with open(nbfile, 'r', encoding='utf-8') as nbf:
        nbdata = nbformat.read(nbf, as_version=4, encoding='utf-8')

    runner = ExecutePreprocessor(timeout=600, kernel_name='probscale')
    runner.preprocess(nbdata, meta)

    img_folder = basename + '_files'
    body_raw, images = RSTExporter().from_notebook_node(nbdata)
    body_final = body_raw.replace('.. image:: ', '.. image:: {}/'.format(img_folder))

    with open(basename + '.rst', 'w', encoding='utf-8') as rst_out:
        rst_out.write(body_final)

    for img_name, img_data in images['outputs'].items():
        img_path = os.path.join(img_folder, img_name)
        with open(img_path, 'wb') as img:
            img.write(img_data) 
开发者ID:matplotlib,项目名称:mpl-probscale,代码行数:23,代码来源:make.py

示例12: test_invalid_notebooks

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def test_invalid_notebooks(
    invalid_notebook_path, cell_location, error_name, error_value, error_output_type
):
    notebook_filename = script_relative_path(invalid_notebook_path)
    with open(notebook_filename) as f:
        nb = nbformat.read(f, as_version=4)
        ep = ExecutePreprocessor(timeout=600, kernel_name='python3')

        try:
            ep.preprocess(
                nb,
                {
                    'metadata': {
                        'path': script_relative_path(
                            notebook_filename[: notebook_filename.rfind('/')]
                        )
                    }
                },
            )
        except CellExecutionError:
            error_message = get_dict_value(nb, cell_location)
            assert error_message.ename == error_name
            assert bool(re.search(error_value, error_message.evalue))
            assert error_message.output_type == error_output_type 
开发者ID:dagster-io,项目名称:dagster,代码行数:26,代码来源:test_jupyter_notebooks.py

示例13: test_reexecute_result_notebook

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def test_reexecute_result_notebook():
    with exec_for_test('define_hello_world_pipeline') as result:
        assert result.success

        materialization_events = [
            x for x in result.step_event_list if x.event_type_value == 'STEP_MATERIALIZATION'
        ]
        for materialization_event in materialization_events:
            result_path = get_path(materialization_event)

        if result_path.endswith('.ipynb'):
            with open(result_path) as fd:
                nb = nbformat.read(fd, as_version=4)
            ep = ExecutePreprocessor()
            ep.preprocess(nb, {})
            with open(result_path) as fd:
                assert nbformat.read(fd, as_version=4) == nb 
开发者ID:dagster-io,项目名称:dagster,代码行数:19,代码来源:test_basic_dagstermill_solids.py

示例14: execute_notebook

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def execute_notebook(ramp_kit_dir='.'):
    import nbformat
    from nbconvert.preprocessors import ExecutePreprocessor

    problem_name = os.path.basename(os.path.abspath(ramp_kit_dir))
    print('Testing if the notebook can be executed')
    notebook_filename = os.path.join(
        os.path.abspath(ramp_kit_dir),
        '{}_starting_kit.ipynb'.format(problem_name))
    kernel_name = 'python{}'.format(sys.version_info.major)

    with open(notebook_filename) as f:
        nb = nbformat.read(f, as_version=4)
        ep = ExecutePreprocessor(timeout=600, kernel_name=kernel_name)
        ep.preprocess(nb, {'metadata':
                           {'path': os.path.abspath(ramp_kit_dir)}}) 
开发者ID:paris-saclay-cds,项目名称:ramp-workflow,代码行数:18,代码来源:notebook.py

示例15: test_notebooks

# 需要导入模块: from nbconvert import preprocessors [as 别名]
# 或者: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
def test_notebooks(nbdir='docs/tutorials/'):
    """
    Run though notebook tutorials
    """

    nbfiles = sorted(glob(os.path.join(nbdir, '*.ipynb')))
    for nbfile in nbfiles:
        print(nbfile)
        with open(nbfile) as f:
            nb = nbformat.read(f, as_version=4)

        if sys.version_info[0] < 3:
            ep = ExecutePreprocessor(timeout=900, kernel_name='python2')
        else:
            ep = ExecutePreprocessor(timeout=900, kernel_name='python3')

        ep.preprocess(nb, {'metadata': {'path': nbdir}}) 
开发者ID:California-Planet-Search,项目名称:radvel,代码行数:19,代码来源:test_nb.py


注:本文中的nbconvert.preprocessors.ExecutePreprocessor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。