Documentation
¶
Overview ¶
Package pipeline composes one source, zero or more transforms and one or more sinks, and walks them in order threading a shared context between them.
Ported from core/pipeline.py. Two things differ deliberately, both noted at the point they occur: Python's Source/Transform/Sink were pure runtime markers and are real types here, and a Go error carries no exception class name, so the failing stage is recorded as its own field rather than being spliced into the message.
Index ¶
- Constants
- Variables
- type Context
- func (c *Context) ConfigBool(key string) bool
- func (c *Context) ConfigString(key string) string
- func (c *Context) Context() context.Context
- func (c *Context) DryRun() bool
- func (c *Context) FetchedPath() (string, bool)
- func (c *Context) FetchedVersion() (string, bool)
- func (c *Context) Logger() *slog.Logger
- func (c *Context) Metric(stage string, values map[string]any)
- func (c *Context) SetFetchedPath(path string)
- func (c *Context) SetFetchedVersion(v string)
- func (c *Context) SetString(key, value string)
- func (c *Context) String(key string) (string, bool)
- type Observer
- type Pipeline
- func (p *Pipeline) Config(kv map[string]any) *Pipeline
- func (p *Pipeline) ConfigValue(key string) (any, bool)
- func (p *Pipeline) Logger(l *slog.Logger) *Pipeline
- func (p *Pipeline) Name() string
- func (p *Pipeline) Observer(o Observer) *Pipeline
- func (p *Pipeline) RunContext(runCtx context.Context) (Result, error)
- func (p *Pipeline) Sink(s Sink) *Pipeline
- func (p *Pipeline) Source(s Source) *Pipeline
- func (p *Pipeline) Stages() []Stage
- func (p *Pipeline) Transform(t Transform) *Pipeline
- func (p *Pipeline) WorkingDir(path string) *Pipeline
- type Result
- type Sink
- type SinkKind
- type Source
- type SourceKind
- type Stage
- type Transform
- type TransformKind
Constants ¶
const ( KeyFetchedPath = "fetched_path" KeyFetchedVersion = "fetched_version" KeyFetchedSource = "fetched_source" KeyCLDRPath = "cldr_path" KeyCLDRText = "cldr_text" KeyCLDRVersion = "cldr_version" KeyCLDRRecords = "cldr_records" KeyFilesystemTgt = "filesystem_target" KeyGitBranch = "git_branch" KeyGitSHA = "git_sha" KeyPRURL = "pr_url" // KeyLicenceFiles is the newline-separated list of upstream licence files // FindLicences found at the root of the fetched tree, as absolute paths to // copies it keeps in the working directory, so a stage that rebuilds the // fetched tree cannot delete them. // Present and empty means it looked and found none. KeyLicenceFiles = "licence_files" // KeyUpstreamRoot is the root of the fetched tree as the source left it, // recorded by FindLicences before anything narrows it, so a stage reading // an upstream data file (Exclude's metadata) still finds it. KeyUpstreamRoot = "upstream_root" )
Well-known Extras keys. These are the contract between stages; the accessors below exist so a typo cannot silently produce a missing value.
const ( ConfigPack = "pack" ConfigPackRoot = "pack_root" ConfigOldVersion = "old_version" // ConfigDryRun is true on every pipeline a dry run builds. The sinks that // write into the pack checkout (Filesystem, LicenceTexts) read it and // report what they would write instead of writing it, so a dry run leaves // the pack byte-identical, tracked and untracked files alike. ConfigDryRun = "dry_run" )
Well-known Config keys, supplied by the recipes.
Variables ¶
var ErrRecipePending = errors.New("recipe pending")
ErrRecipePending is returned for a pack whose recipe has not been written.
No recipe returns it today: every pack in config/ has one, and the aggregator pack runs the manifest-pack recipe. icon-sets-bundled's sync-upstream.yml used to grep the run output for "recipe pending" and turn the failure into a green no-op; that wrapper was removed in icon-sets-bundled#95, so nothing outside this module reads the wording now. It stays so a future pack added before its recipe still fails with a clear message rather than a nil pipeline.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
PipelineName string
WorkingDir string
// Config is the overlay supplied by the builder's Config method. Stages
// read each other's keys, so namespace anything ambiguous.
Config map[string]any
// Extras is free-form scratch space and the real coupling between stages:
// a source drops its extracted tree under FetchedPath, and every transform
// and sink picks it up from there. The well-known keys have typed accessors
// below -- prefer those, because a misspelt string key fails at runtime and
// an accessor fails at compile time.
Extras map[string]any
// Metrics is per-stage counters. The reporter reads this.
Metrics map[string]any
// contains filtered or unexported fields
}
Context is the state threaded through every stage of one run.
Stages mutate Extras to hand data forward. The pipeline guarantees WorkingDir exists for the duration of the run and removes it afterwards when it created it -- so a sink must copy out of it, never move.
func (*Context) ConfigBool ¶ added in v0.1.3
ConfigBool returns a bool-valued config key, or false when absent.
func (*Context) ConfigString ¶
ConfigString returns a string-valued config key, or "" when absent. Callers that need to distinguish absent from empty should read Config directly.
func (*Context) Context ¶ added in v0.1.1
Context returns the run's context.Context. A stage executed outside a pipeline (a test building a Context by hand) gets context.Background().
func (*Context) DryRun ¶ added in v0.1.3
DryRun reports whether this run must leave the pack checkout untouched.
func (*Context) FetchedPath ¶
FetchedPath is the extracted tree a source produced. Every transform and the filesystem sink read it; a stage that needs it and does not find it must fail rather than silently do nothing.
func (*Context) FetchedVersion ¶
FetchedVersion is the upstream version a source actually retrieved. The version stamp and the git sink both key off it.
func (*Context) Logger ¶ added in v0.1.1
Logger returns the logger a stage should write to when it has none of its own: the pipeline's, else slog.Default().
func (*Context) SetFetchedPath ¶
SetFetchedPath records the extracted tree. SubsetTo rewrites it to a subdirectory, which is how a source's `source_path` is honoured.
func (*Context) SetFetchedVersion ¶
SetFetchedVersion records the retrieved version.
type Observer ¶ added in v0.1.1
type Observer interface {
StageStarted(pipeline, stage string)
// StageFinished carries a snapshot of the run's metrics after the stage
// and the stage's error, nil on success.
StageFinished(pipeline, stage string, metrics map[string]any, err error)
}
Observer is told when each stage starts and finishes. It exists so a front-end can draw stage progress from typed events rather than by parsing log lines. Calls arrive on the goroutine running the pipeline.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline is the fluent builder and runner.
func (*Pipeline) ConfigValue ¶ added in v0.1.3
ConfigValue returns one config key as the stages will see it, so a caller can check what a recipe put there without running the pipeline.
func (*Pipeline) Logger ¶
Logger replaces the logger. The TUI swaps in a handler that routes stage lines into the run view instead of stderr.
func (*Pipeline) RunContext ¶ added in v0.1.1
RunContext executes the stages in order and returns the result.
A stage failure stops the run -- the remaining stages do not execute, which is what keeps a sink from committing assets a transform failed to produce.
Cancelling ctx stops the run too: it is checked before every stage, and stages hand it to their subprocesses and downloads. A cancelled run is a failed result whose Err is ctx.Err(), naming the stage it did not start, so a caller can tell a cancel from a fault with errors.Is.
func (*Pipeline) Sink ¶
Sink appends a sink. Any number is valid; the order is load-bearing -- filesystem, then version stamp, then git branch, so the version that is committed is the version that shipped.
func (*Pipeline) Source ¶
Source sets the single source. Setting it twice is an error, surfaced by Run.
func (*Pipeline) Stages ¶
Stages returns the stages in execution order. The TUI reads this to draw a row per stage before the run starts, so a pending stage is visible rather than appearing only once it begins.
func (*Pipeline) WorkingDir ¶
WorkingDir overrides the per-run temporary directory. A caller-supplied directory is left in place afterwards; one the pipeline created is removed.
type Result ¶
type Result struct {
PipelineName string
Success bool
Metrics map[string]any
Extras map[string]any
// Err is the failure, or nil. Python formatted this as
// "RuntimeError: boom"; Go errors carry no class name, so the message
// stands alone and the stage that raised it is recorded separately.
Err error
// FailedStage names the stage that returned Err, empty on success.
FailedStage string
}
Result is what a run returns.
func (Result) Error ¶
Error returns the failure as a string, or "" on success. It is the direct equivalent of Python's PipelineResult.error.
func (Result) Headline ¶ added in v0.1.3
Headline is the one line a person reads for this result: the filesystem sink's counts when there was one, otherwise "finished", or the failure. Summary is the machine payload; printing it with %v produced the "done -- map[error: extras:map[..." line that R3 replaced.
type Sink ¶
type Sink interface {
Stage
// contains filtered or unexported methods
}
Sink writes the in-flight tree to its destination.
type Source ¶
type Source interface {
Stage
// contains filtered or unexported methods
}
Source fetches assets and drops them under Context.WorkingDir.
Python made Source/Transform/Sink empty subclasses of Stage, which the runner then treated identically -- they bought nothing but documentation. Here they are distinct, so passing a sink where a source belongs does not compile. Embed the matching Kind struct to declare which one a stage is.
type SourceKind ¶
type SourceKind struct{}
SourceKind, TransformKind and SinkKind are embedded to declare a stage's role.
type Transform ¶
type Transform interface {
Stage
// contains filtered or unexported methods
}
Transform mutates the in-flight tree under Context.FetchedPath.
type TransformKind ¶
type TransformKind struct{}