starlark

package
v1.233.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 47 Imported by: 0

README

Embedded Starlark runtime

The Starlark package owns language bindings, module loading, component handles, thread management, and parallel callable isolation. Each invocation has its own session; parallel tasks share that session's synchronized output and component cache. The script host owns interpreter registration, invocation normalization, process policy, tool pins, and authored error metadata.

Independent language bindings live under stdlib/:

  • atmos constructs CLI arguments and exposes helpers from a host-supplied command catalog. A callback delegates execution to the engine's process services.
  • log validates structured diagnostics, masks values, and writes to the injected logger. The host supplies step and task attribution.
  • regex implements stateless regular-expression operations.
  • cli translates declarative script arguments and flags into native flag definitions. The standalone CLI host parses them using StandardParser and PositionalArgsBuilder; the binding calls validation and main functions only after parsing succeeds, and skips both for help.

The CLI snapshots its completed command tree through cmd/internal and pkg/flags.CommandCatalog, after custom commands and aliases are registered. This supplies command names, shorthand mappings, and native compatibility flag spellings without importing cmd into the runtime or sharing mutable Cobra objects with concurrent scripts. Actual parsing, validation, environment binding, and command execution still happen in the invoked Atmos binary.

Other embedding hosts can supply WithAtmosCommands. Without a catalog, the explicit atmos.run, atmos.terraform, atmos.helm, and atmos.toolchain helpers remain available; additional named helpers reflect the host's catalog. Explicit flag prefixes pass through unchanged. Bare flags use catalog metadata when available, otherwise the ordinary long-flag spelling.

Keep language-specific operations that depend on invocation state in the engine. Extract bindings when they have independent behavior and a small host interface; do not expose the session struct or split parallel execution away from its cancellation and output lifecycle solely to reduce file counts.

Component resolution and task deadlines

ctx.component is a lazy handle. Reading its attributes resolves the component using the invocation context, because Starlark's attribute interface does not provide the calling thread. The invocation deadline and cancellation still apply; a task-specific timeout does not interrupt this lazy attribute resolution.

For resolution bounded by a task deadline, call components.get inside the task:

def read():
    component = components.get(name="api", stack="dev", type="terraform")
    return component.vars

output = steps.parallel(tasks=[steps.task(name="read", function=read, timeout="5s")])

Both paths share the same per-invocation cache. Successful resolutions are reused; failures can be retried. A components.get caller waiting for another resolver can cancel without waiting for that resolver to finish. Supply the reference directly, or read its fields before starting parallel tasks; reading ctx.component.name inside the task itself would trigger the invocation-scoped resolution first.

Documentation

Overview

Package starlark embeds Starlark with cancellable, isolated parallel tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine contains immutable host services shared by independent invocations.

func New

func New(opts ...Option) *Engine

New creates an embedded engine using Atmos process execution and retry services.

func (*Engine) EvaluateValue

func (e *Engine) EvaluateValue(ctx context.Context, spec script.Evaluation) (any, error)

EvaluateValue evaluates a function body with a read-only configuration context. Wrapping the parsed AST, rather than the source text, preserves YAML line numbers.

func (*Engine) Execute

func (e *Engine) Execute(ctx context.Context, spec script.Spec) (script.Result, error)

Execute runs a script and returns its optional top-level output value: a string is returned as-is, any other value is JSON-encoded.

type Logger

type Logger = logmodule.Logger

Logger is the diagnostics sink behind the log module.

type Option

type Option func(*Engine)

Option configures the host services. Injected services must be concurrency safe.

func WithAtmosCommands

func WithAtmosCommands(catalog *flags.CommandCatalog) Option

WithAtmosCommands supplies an immutable snapshot of the host CLI's command registry.

func WithAtmosExecutable

func WithAtmosExecutable(executable func() (string, error)) Option

WithAtmosExecutable supplies the current Atmos binary lookup for embedded hosts.

func WithFileSystem

func WithFileSystem(fs automation.FileSystem) Option

WithFileSystem supplies read-only filesystem metadata operations.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger supplies the logger behind log.trace/debug/info/warn/error. A nil logger resolves Atmos's current default logger at each call.

func WithProcessRunner

func WithProcessRunner(runner process.Runner) Option

WithProcessRunner supplies the process execution boundary, including test mocks.

func WithReadFile

func WithReadFile(readFile func(string) ([]byte, error)) Option

WithReadFile supplies local module and fs.read_file contents.

func WithRetryClock

func WithRetryClock(clock retry.Clock) Option

WithRetryClock supplies time for retry backoff, including deterministic tests.

func WithTaskObserver

func WithTaskObserver(observe func(TaskEvent)) Option

WithTaskObserver receives serialized branch lifecycle events.

type TaskEvent

type TaskEvent struct {
	Name    string
	Status  string
	Attempt int
	Err     error
}

TaskEvent describes one branch's lifecycle. Attempt is one-based for attempts; status is running, attempt, succeeded, failed, or skipped.

Directories

Path Synopsis
internal
convert
Package convert shares Starlark value conversion and argument diagnostics between the runtime and independent standard-library bindings.
Package convert shares Starlark value conversion and argument diagnostics between the runtime and independent standard-library bindings.
stdlib
cli
Package cli exposes native Atmos command definitions to standalone programs.
Package cli exposes native Atmos command definitions to standalone programs.
digest
Package digest exposes message digests to the Atmos Automation Language.
Package digest exposes message digests to the Atmos Automation Language.
log

Jump to

Keyboard shortcuts

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