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


Python v4.new_notebook方法代码示例

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


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

示例1: tex2ipy

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def tex2ipy(code, cls=Tex2Cells):
    t2c = cls(code)
    cells = t2c.parse()
    livereveal = dict(
        transition='none',
        scroll=True,
        controls=True,
        slideNumber=True,
        help=True
    )
    md = dict(
        language='python',
        celltoolbar='Slideshow',
        livereveal=livereveal
    )
    nb = new_notebook(
        metadata=from_dict(md),
        cells=from_dict(cells)
    )
    return nb 
开发者ID:prabhuramachandran,项目名称:tex2ipy,代码行数:22,代码来源:cli.py

示例2: buildNotebook

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def buildNotebook(appName, result, notebookPath, dataFilePath, runId):
  """
  Method to build .ipynb notebook with init code
   cell for profiles and one report cell per category.

  """
  begin = time.time()
  LOGGER.info('generating notebook %s -> ', os.path.basename(notebookPath))
  nb = nbf.new_notebook()
  numOfCategories, d3Flots = buildReportCells(nb, result, dataFilePath)
  buildInitCell(nb, numOfCategories, d3Flots, appName, runId)

  try:
    with open(notebookPath, 'w') as reportFile:
      nbformat.write(nb, reportFile)
    notebookSize = formatHumanReadable(os.path.getsize(notebookPath))
    elapsed = time.time() - begin
    LOGGER.completed('completed %s in %0.2f sec.', notebookSize, elapsed)
    return True
  except IOError:
    LOGGER.exception('Could not write to the notebook(.ipynb) file')
    return False 
开发者ID:Morgan-Stanley,项目名称:Xpedite,代码行数:24,代码来源:driver.py

示例3: py2ipynb

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def py2ipynb(input, output, cellmark_style, other_ignores=[]):
    """Converts a .py file to a V.4 .ipynb notebook usiing `parsePy` function

    :param input: Input .py filename
    :param output: Output .ipynb filename
    :param cellmark_style: Determines cell marker based on IDE, see parsePy documentation for values
    :param other_ignores: Other lines to ignore
    """
    # Create the code cells by parsing the file in input
    cells = []
    for c in parsePy(input, cellmark_style, other_ignores):
        codecell, metadata, code = c
        cell = new_code_cell(source=code, metadata=metadata) if codecell else new_markdown_cell(source=code, metadata=metadata)
        cells.append(cell)

    # This creates a V4 Notebook with the code cells extracted above
    nb0 = new_notebook(cells=cells,
                       metadata={'language': 'python',})

    with codecs.open(output, encoding='utf-8', mode='w') as f:
        nbformat.write(nb0, f, 4) 
开发者ID:gatsoulis,项目名称:py2ipynb,代码行数:23,代码来源:py2ipynb.py

示例4: combine_notebooks

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def combine_notebooks(notebook_files: Sequence[Path]) -> NotebookNode:
    combined_nb = new_notebook()

    count = 0
    for filename in notebook_files:
        count += 1
        log.debug('Adding notebook: %s', filename)
        nbname = filename.stem
        nb = nbformat.read(str(filename), as_version=4)

        try:
            combined_nb.cells.extend(add_sec_label(nb.cells[0], nbname))
        except NoHeader:
            raise NoHeader("Failed to find header in " + filename)

        combined_nb.cells.extend(nb.cells[1:])

        if not combined_nb.metadata:
            combined_nb.metadata = nb.metadata.copy()

    log.info('Combined %d files' % count)
    return combined_nb 
开发者ID:takluyver,项目名称:bookbook,代码行数:24,代码来源:latex.py

示例5: test_regular_cells

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_regular_cells():
    validator = MetadataValidatorV2()

    # code cell without nbgrader metadata
    cell = create_code_cell()
    validator.validate_cell(cell)
    validator.upgrade_cell_metadata(cell)

    # code cell with metadata, but not an nbgrader cell
    cell = create_regular_cell("", "code", schema_version=2)
    del cell.metadata.nbgrader["task"]
    validator.validate_cell(cell)

    nb = new_notebook()
    cell1 = create_code_cell()
    cell2 = create_regular_cell("", "code", schema_version=2)
    del cell2.metadata.nbgrader["task"]
    nb.cells = [cell1, cell2]
    validator.validate_nb(nb) 
开发者ID:jupyter,项目名称:nbgrader,代码行数:21,代码来源:test_v2.py

示例6: test_regular_cells

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_regular_cells():
    validator = MetadataValidatorV1()

    # code cell without nbgrader metadata
    cell = create_code_cell()
    validator.validate_cell(cell)
    validator.upgrade_cell_metadata(cell)

    # code cell with metadata, but not an nbgrader cell
    cell = create_regular_cell("", "code", schema_version=1)
    del cell.metadata.nbgrader["task"]
    validator.validate_cell(cell)

    nb = new_notebook()
    cell1 = create_code_cell()
    cell2 = create_regular_cell("", "code", schema_version=1)
    del cell2.metadata.nbgrader["task"]
    nb.cells = [cell1, cell2]
    validator.validate_nb(nb) 
开发者ID:jupyter,项目名称:nbgrader,代码行数:21,代码来源:test_v1.py

示例7: test_regular_cells

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_regular_cells():
    validator = MetadataValidatorV3()

    # code cell without nbgrader metadata
    cell = create_code_cell()
    validator.validate_cell(cell)
    validator.upgrade_cell_metadata(cell)

    # code cell with metadata, but not an nbgrader cell
    cell = create_regular_cell("", "code", schema_version=3)
    validator.validate_cell(cell)

    nb = new_notebook()
    cell1 = create_code_cell()
    cell2 = create_regular_cell("", "code", schema_version=3)
    nb.cells = [cell1, cell2]
    validator.validate_nb(nb) 
开发者ID:jupyter,项目名称:nbgrader,代码行数:19,代码来源:test_v3.py

示例8: test_grade_correct_code

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_grade_correct_code(self, preprocessors, gradebook, resources):
        """Is a passing code cell correctly graded?"""
        cell = create_grade_cell("hello", "code", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)

        grade_cell = gradebook.find_grade("foo", "test", "ps0", "bar")
        assert grade_cell.score == 1
        assert grade_cell.max_score == 1
        assert grade_cell.auto_score == 1
        assert grade_cell.manual_score == None
        assert not grade_cell.needs_manual_grade 
开发者ID:jupyter,项目名称:nbgrader,代码行数:18,代码来源:test_saveautogrades.py

示例9: test_grade_incorrect_code

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_grade_incorrect_code(self, preprocessors, gradebook, resources):
        """Is a failing code cell correctly graded?"""
        cell = create_grade_cell("hello", "code", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        cell.outputs = [new_output('error', ename="NotImplementedError", evalue="", traceback=["error"])]
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)

        grade_cell = gradebook.find_grade("foo", "test", "ps0", "bar")
        assert grade_cell.score == 0
        assert grade_cell.max_score == 1
        assert grade_cell.auto_score == 0
        assert grade_cell.manual_score == None
        assert not grade_cell.needs_manual_grade 
开发者ID:jupyter,项目名称:nbgrader,代码行数:19,代码来源:test_saveautogrades.py

示例10: test_grade_unchanged_markdown

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_grade_unchanged_markdown(self, preprocessors, gradebook, resources):
        """Is an unchanged markdown cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)

        grade_cell = gradebook.find_grade("foo", "test", "ps0", "bar")
        assert grade_cell.score == 0
        assert grade_cell.max_score == 1
        assert grade_cell.auto_score == 0
        assert grade_cell.manual_score == None
        assert not grade_cell.needs_manual_grade 
开发者ID:jupyter,项目名称:nbgrader,代码行数:18,代码来源:test_saveautogrades.py

示例11: test_grade_changed_markdown

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_grade_changed_markdown(self, preprocessors, gradebook, resources):
        """Is a changed markdown cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        cell.source = "hello!"
        preprocessors[1].preprocess(nb, resources)

        grade_cell = gradebook.find_grade("foo", "test", "ps0", "bar")
        assert grade_cell.score == 0
        assert grade_cell.max_score == 1
        assert grade_cell.auto_score == None
        assert grade_cell.manual_score == None
        assert grade_cell.needs_manual_grade 
开发者ID:jupyter,项目名称:nbgrader,代码行数:19,代码来源:test_saveautogrades.py

示例12: test_grade_existing_auto_comment

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_grade_existing_auto_comment(self, preprocessors, gradebook, resources):
        """Is a failing code cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)

        comment = gradebook.find_comment("foo", "test", "ps0", "bar")
        assert comment.auto_comment == "No response."

        nb.cells[-1].source = 'goodbye'
        preprocessors[1].preprocess(nb, resources)

        gradebook.db.refresh(comment)
        assert comment.auto_comment is None 
开发者ID:jupyter,项目名称:nbgrader,代码行数:20,代码来源:test_saveautogrades.py

示例13: test_invalid_grade_cell_id

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_invalid_grade_cell_id(self, preprocessor):
        """Check that an error is raised when the grade cell id is invalid"""
        resources = dict(grade_ids=[])
        nb = new_notebook()

        nb.cells = [create_grade_cell("", "code", "", 1)]
        with pytest.raises(ValidationError):
            preprocessor.preprocess(nb, resources)

        nb.cells = [create_grade_cell("", "code", "a b", 1)]
        with pytest.raises(ValidationError):
            preprocessor.preprocess(nb, resources)

        nb.cells = [create_grade_cell("", "code", "a\"b", 1)]
        with pytest.raises(ValidationError):
            preprocessor.preprocess(nb, resources)

        nb.cells = [create_solution_cell("", "code", "abc-ABC_0")]
        preprocessor.preprocess(nb, resources) 
开发者ID:jupyter,项目名称:nbgrader,代码行数:21,代码来源:test_checkcellmetadata.py

示例14: test_overwrite_kernelspec

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_overwrite_kernelspec(self, preprocessors, resources, gradebook):
        kernelspec = dict(
            display_name='blarg',
            name='python3',
            language='python',
        )

        nb = new_notebook()
        nb.metadata['kernelspec'] = kernelspec
        nb, resources = preprocessors[0].preprocess(nb, resources)

        nb.metadata['kernelspec'] = {}
        nb, resources = preprocessors[1].preprocess(nb, resources)

        validate(nb)
        notebook = gradebook.find_notebook("test", "ps0")
        assert nb.metadata['kernelspec'] == kernelspec
        assert json.loads(notebook.kernelspec) == kernelspec 
开发者ID:jupyter,项目名称:nbgrader,代码行数:20,代码来源:test_overwritekernelspec.py

示例15: test_save_code_grade_cell

# 需要导入模块: from nbformat import v4 [as 别名]
# 或者: from nbformat.v4 import new_notebook [as 别名]
def test_save_code_grade_cell(self, preprocessor, gradebook, resources):
        cell = create_grade_cell("hello", "code", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)

        nb, resources = preprocessor.preprocess(nb, resources)

        grade_cell = gradebook.find_grade_cell("foo", "test", "ps0")
        assert grade_cell.max_score == 1
        assert grade_cell.cell_type == "code"

        source_cell = gradebook.find_source_cell("foo", "test", "ps0")
        assert source_cell.source == "hello"
        assert source_cell.checksum == cell.metadata.nbgrader["checksum"]
        assert source_cell.cell_type == "code"
        assert source_cell.locked 
开发者ID:jupyter,项目名称:nbgrader,代码行数:19,代码来源:test_savecells.py


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