notebook

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package notebook reads the code cells of a Jupyter notebook (nbformat 4), so a model written in a notebook can be loaded where a model file can.

Index

Constants

View Source
const Ext = ".ipynb"

Ext is the file extension a notebook is named with.

View Source
const Language = "sysml"

Language is the kernelspec language a notebook must record to be loaded as a SysML model; a notebook recording none is taken to be one.

View Source
const SkipTag = "skip-load"

SkipTag marks a code cell a load passes over: scratch work, a demonstration, anything the notebook runs that another should not inherit.

Variables

This section is empty.

Functions

func IsNotebook

func IsNotebook(path string) bool

IsNotebook reports whether path names a notebook, by its extension.

Types

type Cell

type Cell struct {
	// Index is the cell's 1-based position among the notebook's code cells,
	// which is how a selection names it and how a diagnostic locates it.
	Index  int
	Source string
	Tags   []string
}

Cell is one code cell of a notebook.

func (Cell) Tagged

func (c Cell) Tagged(tag string) bool

Tagged reports whether the cell carries tag in its metadata.

type FormatError

type FormatError struct {
	Name   string
	Reason string
}

FormatError is a file that is not a notebook a load can read, and why.

func (*FormatError) Error

func (e *FormatError) Error() string

type LanguageError

type LanguageError struct {
	Name     string
	Language string
}

LanguageError is a notebook written for another kernel's language, which a load refuses rather than reading its cells as SysML.

func (*LanguageError) Error

func (e *LanguageError) Error() string

type Notebook

type Notebook struct {
	Name     string
	Language string // kernelspec.language, else language_info.name; "" when neither is recorded
	Cells    []Cell
}

Notebook is what a load reads of a notebook: its code cells in notebook order, markdown and raw cells left out, and the language its kernel records.

func Parse

func Parse(name string, data []byte) (*Notebook, error)

Parse reads data as the nbformat 4 notebook called name. A notebook of another format version, or a file that is not a notebook at all, is a *FormatError; one written for another language is a *LanguageError.

func Read

func Read(path string) (*Notebook, error)

Read reads the notebook at path. The error is a *FormatError for a file that is not an nbformat 4 notebook, or the read error.

type Selection

type Selection struct {
	// contains filtered or unexported fields
}

Selection picks the code cells of a notebook a load reads: by position among the code cells, 1-based, as `1,3-5`, or by a tag they carry, as `tag:model`. The zero Selection picks every cell.

func ParseSelection

func ParseSelection(text string) (Selection, error)

ParseSelection reads a selection as it is written after `--cells`.

func (Selection) Apply

func (s Selection) Apply(nb *Notebook) ([]Cell, error)

Apply picks the notebook's cells the selection names, in notebook order. A position past the notebook's code cells is an error naming how many there are; a tag no cell carries is an error naming the tag.

func (Selection) IsZero

func (s Selection) IsZero() bool

IsZero reports whether the selection picks every cell.

func (Selection) String

func (s Selection) String() string

String is the selection as it was written.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL