notebook

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

This file is define ipython notebook format see more https://nbformat.readthedocs.io/en/latest/format_description.html

Index

Constants

View Source
const (
	ImportNotebooks = "ImportNotebooks"
)

Variables

This section is empty.

Functions

func NameOfPath

func NameOfPath(name string) string

NameOfPath ...

func NamespaceOfPath

func NamespaceOfPath(name string) string

NamespaceOfPath ...

func Path

func Path(namespace, name string) string

Path ...

Types

type CreateParam

type CreateParam struct {
	Name        string
	WorkspaceID string
	Content     []byte
}

type Factory

type Factory struct {
}

func NewFactory

func NewFactory() *Factory

func (*Factory) New

func (f *Factory) New(param *CreateParam) (*Notebook, error)

type IPythonNotebook

type IPythonNotebook struct {
	Meta        IPythonNotebookMeta   `json:"metadata"`
	Cells       []IPythonNotebookCell `json:"cells"`
	Format      int                   `json:"nbformat" validate:"required,min=4"`
	FormatMinor int                   `json:"nbformat_minor"`
}

type IPythonNotebookCell

type IPythonNotebookCell struct {
	ID             string                      `json:"id"`
	Type           string                      `json:"cell_type" validate:"required,oneof=code markdown raw"`
	Meta           map[string]interface{}      `json:"metadata"`
	ExecutionCount *int                        `json:"execution_count"`
	Source         []string                    `json:"source"`
	Outputs        []IPythonNotebookCellOutput `json:"outputs"`
	Attachments    map[string]interface{}      `json:"attachments"`
}

type IPythonNotebookCellOutput

type IPythonNotebookCellOutput struct {
	Type string `json:"output_type" validate:"required,oneof=stream display_data execute_result error"`
	Name string `json:"name" validate:"required"`

	Text []string `json:"text"`

	// in display data
	Meta map[string]interface{} `json:"metadata"`
	Data map[string]interface{} `json:"data"`

	// in execute result; used to be pyout / prompt_number
	ExecutionCount int `json:"execute_count"`

	// In errors
	EName     string   `json:"ename"`
	EValue    string   `json:"evalue"`
	Traceback []string `json:"traceback"`
}

type IPythonNotebookKernelSpec

type IPythonNotebookKernelSpec struct {
	Name        string `json:"name" validate:"required"`
	DisplayName string `json:"display_name"`
	Language    string `json:"language" validate:"required,oneof=python R"`
}

type IPythonNotebookLanguageInfo

type IPythonNotebookLanguageInfo struct {
	Name          string `json:"name" validate:"required,oneof=python R"`
	Version       string `json:"version" validate:"required"`
	PygmentsLexer string `json:"pygments_lexer"`
	// codemirror_mode in docs is string but jupyter created is {"name":"ipython",...}
	// CodeMirrorMode string `json:"codemirror_mode"`
	FileExtension string `json:"file_extension" validate:"required"`
	MimeType      string `json:"mimetype" validate:"required"`
}

type IPythonNotebookMeta

type IPythonNotebookMeta struct {
	LanguageInfo IPythonNotebookLanguageInfo `json:"language_info"`
	KernelSpec   IPythonNotebookKernelSpec   `json:"kernelspec"`
	MaxCellID    int                         `json:"max_cell_id"`
}

type ImportNotebooksEvent

type ImportNotebooksEvent struct {
	WorkspaceID       string
	Schema            schema.NotebookTypedSchema
	ImportFileBaseDir string
}

func NewImportNotebooksEvent

func NewImportNotebooksEvent(workspaceID, baseDir string, schema schema.NotebookTypedSchema) *ImportNotebooksEvent

func NewImportNotebooksEventFromPayload

func NewImportNotebooksEventFromPayload(data []byte) (*ImportNotebooksEvent, error)

func (*ImportNotebooksEvent) Delay

func (e *ImportNotebooksEvent) Delay() time.Duration

func (*ImportNotebooksEvent) EventType

func (e *ImportNotebooksEvent) EventType() string

func (*ImportNotebooksEvent) Payload

func (e *ImportNotebooksEvent) Payload() []byte

type Notebook

type Notebook struct {
	Name       string
	Namespace  string
	Content    []byte
	UpdateTime time.Time
}

Notebook is domain object

func (*Notebook) Path

func (n *Notebook) Path() string

Path return unique path of notebook, e.g. {workspace-id}/{name}

type Repository

type Repository interface {
	Save(context.Context, *Notebook) error
	Get(context.Context, string) (*Notebook, error)
	Delete(context.Context, *Notebook) error
}

Repository allows to get/save events from/to event store.

type Service

type Service interface {
	Upsert(context.Context, *Notebook) error
	Create(context.Context, *Notebook) error
	Update(context.Context, *Notebook) error
	Delete(ctx context.Context, path string) error
}

func NewService

func NewService(repo Repository) Service

Jump to

Keyboard shortcuts

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