Notebook

class pynblint.notebook.Notebook(path: pathlib.Path)[source]

This class stores the representations of a notebook on which pynblint functions are called

Notebook Linting

Linting functions for notebooks.

pynblint.nb_linting.cells_too_long(notebook: pynblint.notebook.Notebook) List[pynblint.cell.Cell][source]

Check whether code cells in this notebook are too long.

pynblint.nb_linting.duplicate_notebook_not_renamed(notebook: pynblint.notebook.Notebook) bool[source]

Check if the duplicate notebook has not been renamed.

I.e., if it was left with the default title: <source-notebook-name>-Copy<copy-number>.ipynb. :param notebook: the notebook to be analyzed. :type notebook: Notebook

Returns

True if the notebook was left with the default title;

False otherwise.

Return type

bool

pynblint.nb_linting.empty_cells(notebook: pynblint.notebook.Notebook) List[pynblint.cell.Cell][source]

Check the existence of empty cells and return their list.

pynblint.nb_linting.imports_beyond_first_cell(notebook: pynblint.notebook.Notebook) bool[source]

Check if import statements are used beyond the first code cell.

pynblint.nb_linting.invalid_python_syntax(notebook: pynblint.notebook.Notebook) bool[source]

Check if the notebook contains invalid Python syntax in code cells.

Parameters

notebook (Notebook) – the notebook to be analyzed.

Returns

True if the notebook contains invalid Python syntax (as detected by ast.parse); False otherwise.

Return type

bool

pynblint.nb_linting.long_filename(notebook: pynblint.notebook.Notebook) bool[source]

Check if the notebook title exceedes the fixed character threshold.

pynblint.nb_linting.missing_closing_MD_text(notebook: pynblint.notebook.Notebook) bool[source]

Check that descriptive MD cells are present among the first cells of a notebook.

Markdown cells containing just Markdown headings do not count.

Parameters

notebook (Notebook) – the notebook to be analyzed.

Returns

True if the notebook has no MD cells among its fist cells;

False otherwise.

Return type

bool

pynblint.nb_linting.missing_h1_md_heading(notebook: pynblint.notebook.Notebook) bool[source]

Check that the notebook has an H1 Markdown title in the initial cells.

Parameters

notebook (Notebook) – the notebook to be analyzed.

Returns

True if the notebook does not contain an H1 title in the selected set

of initial cells; False otherwise.

Return type

bool

pynblint.nb_linting.missing_opening_MD_text(notebook: pynblint.notebook.Notebook) bool[source]

Check that descriptive MD cells are present among the first cells of a notebook.

Markdown cells containing just Markdown headings do not count.

Parameters

notebook (Notebook) – the notebook to be analyzed.

Returns

True if the notebook has no MD cells among its fist cells;

False otherwise.

Return type

bool

pynblint.nb_linting.non_executed_cells(notebook: pynblint.notebook.Notebook) List[pynblint.cell.Cell][source]

Check the existence of non executed cells and return their list.

pynblint.nb_linting.non_linear_execution(notebook: pynblint.notebook.Notebook) bool[source]

Check linear execution order of notebook cells.

pynblint.nb_linting.notebook_named_with_unrestricted_charset(notebook: pynblint.notebook.Notebook) bool[source]

Check if the notebook filename contains characters outside [A-Za-z0-9_.-].

To be supported by all popular operating systems, notebook names should be restricted to the [A-Za-z0-9_.-] charset.

pynblint.nb_linting.notebook_too_long(notebook: pynblint.notebook.Notebook) bool[source]

Check if the notebook is too long (i.e., if it contains too many cells).

pynblint.nb_linting.too_few_MD_cells(notebook: pynblint.notebook.Notebook) bool[source]

Check that the number of MD cells is adequate.

Check that the number of MD cells is adequate with respect to the number of code cells.

Parameters

notebook (Notebook) – the notebook to be analyzed.

Returns

True if the notebook contains too few MD cells with respect to the existing code cells; False otherwise.

Return type

bool

pynblint.nb_linting.untitled_notebook(notebook: pynblint.notebook.Notebook) bool[source]

Check whether the notebook is untitled. I.e., The notebook still has the default title:

“Untitled[<number>].ipynb”,

Args:

notebook (Notebook): the notebook to be analyzed.

Returns

True if the notebook was left with the default creation title;

False otherwise.

Return type

bool