sphinxcontrib-jupyter icon indicating copy to clipboard operation
sphinxcontrib-jupyter copied to clipboard

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

Open mmcky opened this issue 7 years ago • 0 comments
trafficstars

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.

mmcky avatar Oct 11 '18 04:10 mmcky