starlark

package
v2.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package starlark runs Pachyderm-specific starlark programs. It's recommended to import this as "ourstar" when also using go.starlark.net/starlark in the same package.

Index

Constants

This section is empty.

Variables

View Source
var Personality = personality{
	Name:    "",
	Options: Options{},
}

Personality is the personality selected from the command line.

Functions

func Error

func Error(name string, err error) []zap.Field

func FromStarlark

func FromStarlark(v starlark.Value) any

FromStarlark returns a Go value for a Starlark value.

func GetContext

func GetContext(t *starlark.Thread) context.Context

GetContext returns a context.Context that applies to in the provided Starlark thread.

func ReflectList

func ReflectList[T any](xs []T) *starlark.List

ReflectList returns a starlark.List from any Go slice.

func RegisterPersonality

func RegisterPersonality(name string, opts Options)

RegisterPersonality registers a personality; intended to be called from the init() section of modules that provide starlark bindings.

func Run

func Run(rctx context.Context, in string, opts Options, f RunFunc) (starlark.StringDict, error)

Run runs the provided RunFunc. The input "in" is not run here, and only serves as a base path for resolving module loads.

func RunProgram

func RunProgram(ctx context.Context, path string, opts Options) (starlark.StringDict, error)

RunProgram runs an on-disk Starlark script located at path.

func RunScript

func RunScript(ctx context.Context, name string, script string, opts Options) (starlark.StringDict, error)

RunScript runs a script named "name" from the program text in "script".

func RunShell

func RunShell(ctx context.Context, path string, opts Options) error

func Stack

func Stack(name string, stack starlark.CallStack) zap.Field

func Union

func Union(dicts ...starlark.StringDict) starlark.StringDict

func UsePersonalityFlag

func UsePersonalityFlag(flagset *pflag.FlagSet)

UsePersonalityFlag registers DefaultPersonality with the provided flagset.

func Value

func Value(in any) starlark.Value

Value makes any Go value available to Starlark.

Types

type Any

type Any struct{ Value any }

Any is an `any` that can be unpacked into

func (*Any) Unpack

func (x *Any) Unpack(v starlark.Value) error

type Options

type Options struct {
	// Modules are built-in modules that are available for programs to load with "load".
	// "*.star" is always resolve to a disk path; everything else can be a key in this map.  The
	// StringDict map value should be a map from function names to starlark.Builtin objects.
	Modules map[string]starlark.StringDict
	// Predefined is a dictionary of predefined values that don't need to be loaded.
	Predefined starlark.StringDict
	// REPLPredefined are values that are only predefined in an interactive shell.
	REPLPredefined starlark.StringDict
	// ThreadLocalVars are additional thread-local variables to set.  Go code can get at these
	// environment variables with thread.Local(key).  See GetContext() for an example.
	ThreadLocalVars map[string]any
}

Options controls the Starlark execution environment.

type Reflect

type Reflect struct {
	Any any
}

Reflect is a starlark.Value that exposes the fields of struct types. For example, `package foo; struct Test { Foo string }` would be of type "foo.Test" and have one attribute, "Foo", in starlark, used like value.Foo.

func (*Reflect) Attr

func (r *Reflect) Attr(name string) (starlark.Value, error)

func (*Reflect) AttrNames

func (r *Reflect) AttrNames() []string

func (*Reflect) Cmp

func (r *Reflect) Cmp(y starlark.Value, _ int) (int, error)

func (*Reflect) Freeze

func (r *Reflect) Freeze()

func (*Reflect) Get

func (r *Reflect) Get(v starlark.Value) (starlark.Value, bool, error)

func (*Reflect) Hash

func (r *Reflect) Hash() (uint32, error)

func (*Reflect) String

func (r *Reflect) String() string

func (*Reflect) Truth

func (r *Reflect) Truth() starlark.Bool

func (*Reflect) Type

func (r *Reflect) Type() string

type RunFunc

type RunFunc func(fileOpts *syntax.FileOptions, thread *starlark.Thread, in string, module string, globals starlark.StringDict) (starlark.StringDict, error)

RunFunc is a function that can run a Starlark program in a thread. in is the string passed to Run, module is the canonical module name for that code, if applicable.

type ToGoer

type ToGoer interface {
	ToGo() any
}

ToGo is an interface for starlark.Values that can turn themselves into Go.

Directories

Path Synopsis
lib
k8s
Package k8s is a Kubernetes API binding for Starlark.
Package k8s is a Kubernetes API binding for Starlark.
Package starcmp provides utilities for running cmp.Diff on Starlark values.
Package starcmp provides utilities for running cmp.Diff on Starlark values.

Jump to

Keyboard shortcuts

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