magus v0.4.3 is out. See what's new
¶ View generated markdown
4 min read

pipe

Read the records a magus stage upstream in a pipe writes, and write records for the stage downstream.

Naming convention: import the module under its bare name (import "pipe"), reach members with a backslash, and call methods in camelCase: pipe\someMethod.

Note

The examples below are reference-only. pipe performs real IO (filesystem, process, network, or environment access) that the in-browser playground's sandbox cannot provide, so it is not registered there and its examples have no Run button. Pure-compute modules such as strings and json run their examples live in the page.

Methods

more

Report whether another record is coming from the magus stage writing this script's stdin, waiting for it or for that stage to end. Errors when no magus stage writing records feeds this script.

Signature: pipe\more() -> bool - source

Returns: bool

Example:

import "std";
import "pipe";

// magus run test . | magus buzz failures.buzz
// more waits for the next record, so each failure prints as the run reports it.
try {
    while (pipe\more()) {
        final rec = pipe\next();
        if (rec.@"type" == "run.target.result" and rec.status == "failed") {
            std\print("FAIL {rec.project}:{rec.target}  magus query output {rec.ref}");
        }
    }
} catch (e) {
    std\print("no magus run is piped into this script");
}

next

Return the next record from the magus stage writing this script's stdin, waiting for it. Errors past the last record, and when no magus stage writing records feeds this script.

Signature: pipe\next() -> PipeRecord - source

Returns: map[string]any

all

Return every record not yet read, once the magus stage writing this script's stdin has ended. Errors when no magus stage writing records feeds this script.

Signature: pipe\all() -> [PipeRecord] - source

Returns: any

emit

Write record to stdout for the stage downstream. A record read from upstream passes through byte for byte; one built here is written from its fields, and needs a type. A run.scope record's projects are what a run downstream that names none runs on.

Signature: pipe\emit(record) - source

Parameter Type Optional Description
record map[string]any

Example:

import "std";
import "pipe";

// magus run test . | magus buzz retry.buzz | magus run test
// A run.scope record names the projects a run downstream runs on when it names none,
// so this passes on only the projects that failed.
try {
    var failed: mut [str] = mut [];
    foreach (rec in pipe\all()) {
        if (rec.@"type" == "run.target.result" and rec.status == "failed") {
            failed.append(rec.project);
        }
    }
    pipe\emit(pipe\PipeRecord{ @"type" = "run.scope", projects = failed });
} catch (e) {
    std\print("no magus run is piped into this script");
}

outputs

Return the files the target of record declared as outputs and that exist on disk now, sorted by workspace-relative path. record names a project and a target, like a run.target.result.

Signature: pipe\outputs(record) -> [Artifact] - source

Parameter Type Optional Description
record map[string]any

Returns: any

Example:

import "std";
import "pipe";

// magus run build . | magus buzz export.buzz
// Copies every file the build declared and produced under dist-copy/, keeping the tree.
try {
    foreach (rec in pipe\all()) {
        if (rec.@"type" == "run.target.result") {
            foreach (a in pipe\outputs(rec)) {
                std\print(pipe\exportTo(a, dest: "dist-copy/{a.path}"));
            }
        }
    }
} catch (e) {
    std\print("no magus run is piped into this script");
}

exportTo

Copy artifact to dest, keeping its mode, and return dest. It writes a temporary file beside dest and renames it into place, so a symlink at dest is replaced rather than written through and an artifact exported onto itself survives.

Signature: pipe\exportTo(artifact, dest) -> string - source

Parameter Type Optional Description
artifact map[string]any
dest string

Returns: string

history

Return every version of artifact the cache stored, newest first, with identical consecutive content collapsed: when its bytes changed, which its VCS history cannot say.

Signature: pipe\history(artifact) -> [ArtifactVersion] - source

Parameter Type Optional Description
artifact map[string]any

Returns: any

diff

Compare artifact on disk against its most recent different cached version with your difftool: $MAGUS_DIFFTOOL, else $DIFFTOOL, else git diff --no-index. It renders nothing itself.

Signature: pipe\diff(artifact) - source

Parameter Type Optional Description
artifact map[string]any

value

Return what a target returned, a str or a [str], from its run.target.value record. Errors for any other record.

Signature: pipe\value(record) -> any - source

Parameter Type Optional Description
record map[string]any

Returns: any

generatedreference/buzz/pipemodulestdlibmagusfile
Last updated (a9ff8609)
Earlier changes on this page (1)

Full history ↗ · Blame source ↗

Glossary

Workspace

The magus root directory that owns a set of projects and shared config; the unit magus operates over. See workspace.

Project

A directory magus recognizes as a unit of work (it has a magusfile); the unit of caching, scheduling, and dependency tracking. See workspace.

Magusfile

The magusfile.buzz that declares a project's targets (as export funs) and binds its spells. See targets.

Target

A named operation (build, test, ...) you invoke with magus run <target>; it may compose a spell's tool-native operations and depend on other targets. See targets.

Op

A single tool-native command a target composes (long form: operation); the middle of the work hierarchy (Spell to Op to Target). See operations.

Module

A magus stdlib namespace a magusfile imports for host capabilities: filesystem, exec, vcs, and more. See the module reference.

Buzz

The language magusfiles are written in (the .buzz engine). See engines.

Cache

The content-addressed store magus consults before running a target, so unchanged work is skipped. See cache.

Sandbox

The restricted filesystem and environment a target runs in, so builds stay reproducible and side-effect-free. See sandbox.

Run

One target executing under one magus invocation, such as magus run test web or magus affected ci. A run keeps its captured output behind an output reference. Every magus run is a run whether or not any job asked for it; see Job for how the two relate.

Conventions

Admonitions

Call-outs are rendered from GitHub-style alert blockquotes and carry a colored accent per type:

Note

Context worth knowing, but not a warning.

Warning

Something that can bite you if ignored.

The types are NOTE, TIP, IMPORTANT, WARNING, and CAUTION.