Skip to content

ENH: Improve implementation for handling :no-execute: code blocks #130

@mmcky

Description

@mmcky

Add :no-execute: to cell metadata and write a nbconvert pre-parser to skip execution as an alternative to the current implementation of :class: no-execute.

class MyExecutePreprocessor(nbconvert.preprocessors.ExecutePreprocessor):

    def preprocess_cell(self, cell, resources, cell_index):
        """
        Executes a single code cell. See base.py for details.
        To execute all cells see :meth:`preprocess`.

        Checks cell.metadata for 'execute' key. If set, and maps to False, 
          the cell is not executed.
        """

        if not cell.metadata.get('execute', True):
            # Don't execute this cell in output
            return cell, resources

        return super().preprocess_cell(cell, resources, cell_index)

(as per: https://stackoverflow.com/questions/26494747/simple-way-to-choose-which-cells-to-run-in-ipython-notebook-during-run-all/43584169)

  • For the .. jupyter:: directive we can add :allow-error: for cell-blocks that should execute (when compiling the website) but don't execute when running the coverage test suite. In the future we could add error types such as ValueError to catch only specific error types etc. For now it will be just a boolean flag. It is also pretty self explanatory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions