starlark

package
v0.1.0-dev.20260314201016 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package starlark provides the Starlark scripting runtime for devlore.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PackageContext

type PackageContext struct {
	// Name is the package name being deployed.
	Name string

	// Version is the version being deployed.
	Version string

	// Features are the enabled feature flags for this deployment.
	Features []string

	// Settings are key-value configuration settings.
	Settings map[string]string

	// DryRun indicates this is a preview (no actual changes).
	DryRun bool

	// SourceRoot is the package source directory in the registry cache.
	SourceRoot string

	// TargetRoot is the deployment target directory (usually $HOME).
	TargetRoot string
}

PackageContext provides information about the package being deployed. Passed to phase scripts as the first argument.

func (*PackageContext) HasFeature

func (p *PackageContext) HasFeature(name string) bool

HasFeature checks if a feature is enabled.

func (*PackageContext) Setting

func (p *PackageContext) Setting(key string) string

Setting returns a setting value, or empty string if not set.

func (*PackageContext) ToStarlark

func (p *PackageContext) ToStarlark() starlark.Value

ToStarlark converts the PackageContext to a Starlark receiver.

type PhaseContext

type PhaseContext struct {
	// PhaseName is the lifecycle phase (e.g., "install", "provision").
	PhaseName string

	// Action is the lifecycle action (e.g., "deploy", "remove").
	Action string

	// Retry holds the retry policy configured by the script.
	Retry *op.RetryPolicy
}

PhaseContext provides phase metadata to lifecycle scripts.

Passed as the second call argument: def install(package, phase):

Starlark API:

phase.name # Phase name (e.g., "install", "provision")
phase.action # Lifecycle action (e.g., "deploy", "remove")
phase.retry(max_attempts=3, backoff="exponential") # Configures retry policy

func (*PhaseContext) ToStarlark

func (c *PhaseContext) ToStarlark() starlark.Value

ToStarlark returns a Starlark value exposing phase.name, phase.action, phase.retry().

type PlanRoot

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

PlanRoot implements the top-level plan namespace using the slot-based model. Sub-namespaces are populated from PlanningReceiverFactory implementations selected by Runtime. Flow actions (choose, source, gather) are built-in.

func NewPlanRootFromProviders

func NewPlanRootFromProviders(graph *op.Graph, project string, reg *op.ActionRegistry, providers map[string]op.PlanningReceiverFactory) *PlanRoot

NewPlanRootFromProviders creates a PlanRoot from announced PlanningReceiverFactory implementations. Consumers select providers via Runtime, which passes the filtered provider map here.

func (*PlanRoot) Attr

func (p *PlanRoot) Attr(name string) (starlark.Value, error)

Attr implements starlark.HasAttrs.

func (*PlanRoot) AttrNames

func (p *PlanRoot) AttrNames() []string

AttrNames implements starlark.HasAttrs.

func (*PlanRoot) Freeze

func (p *PlanRoot) Freeze()

Freeze implements starlark.Value.

func (*PlanRoot) Hash

func (p *PlanRoot) Hash() (uint32, error)

Hash implements starlark.Value.

func (*PlanRoot) String

func (p *PlanRoot) String() string

String implements starlark.Value.

func (*PlanRoot) Truth

func (p *PlanRoot) Truth() starlark.Bool

Truth implements starlark.Value.

func (*PlanRoot) Type

func (p *PlanRoot) Type() string

Type implements starlark.Value.

type Runtime

type Runtime struct {
	*op.StarlarkRuntime
	// contains filtered or unexported fields
}

Runtime is the devlore Starlark runtime. It embeds op.StarlarkRuntime for immediate receiver management and adds the plan namespace and @devlore// module loader used by the CLI tools.

func NewRuntime

func NewRuntime(cfg *op.BindingConfig) *Runtime

NewRuntime creates a Runtime with the given configuration. Receivers listed in cfg.Receivers are included as pre-injected globals.

Parameters:

  • cfg: configuration specifying providers, writer, and program name.

Returns:

  • *Runtime: the initialized runtime.

func (*Runtime) BuildGlobals

func (rt *Runtime) BuildGlobals(graph *op.Graph, project string, reg *op.ActionRegistry) starlark.StringDict

BuildGlobals constructs the Starlark globals dict for a consumer. Only receivers listed in cfg.Receivers appear as globals. If GraphBuilder is enabled, a PlanRoot is built from all announced PlanningReceiverFactory implementations.

Parameters:

  • graph: the execution graph for plan namespace construction.
  • project: the project name passed to planned providers.
  • reg: the action registry for plan namespace construction.

Returns:

  • starlark.StringDict: the complete globals dict for Starlark execution.

func (*Runtime) ConfigureThread

func (rt *Runtime) ConfigureThread(thread *starlark.Thread, graph *op.Graph, project string, reg *op.ActionRegistry)

ConfigureThread sets thread.Load to the @devlore// module loader. The loader resolves provider names from the runtime and caches instances. Must be called before starlark.ExecFileOptions.

Parameters:

  • thread: the Starlark thread to configure.
  • graph: the execution graph for module resolution.
  • project: the project name for module resolution.
  • reg: the action registry for module resolution.

func (*Runtime) NewPopulatedRegistry

func (rt *Runtime) NewPopulatedRegistry(ctx op.Context) *op.ActionRegistry

NewPopulatedRegistry creates an ActionRegistry with all provider actions registered. Shorthand for NewActionRegistry() + RegisterActions().

Parameters:

  • ctx: the execution context for provider initialization.

Returns:

  • *op.ActionRegistry: the populated registry.

func (*Runtime) RegisterActions

func (rt *Runtime) RegisterActions(reg *op.ActionRegistry, ctx op.Context)

RegisterActions registers all providers' actions with the registry. All providers' actions are always registered regardless of Providers selections — the action registry is for the executor, not the script environment.

Parameters:

  • reg: the action registry to populate.
  • ctx: the execution context for provider initialization.

Jump to

Keyboard shortcuts

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