Skip to content

stepup.core.stepinfo

Information about a step in a StepUp build, intended for defining follow-up steps.

StepInfo

Information about a step in a StepUp build, intended for defining follow-up steps.

This object does not contain any dynamic dependency information. It only holds initial dependencies known at the time the step is defined.

All paths and environment variable names are stored in sorted order to ensure consistency. If paths are relative, they should be relative to the work directory.

Source code in stepup/core/stepinfo.py
@attrs.define
class StepInfo:
    """Information about a step in a StepUp build, intended for defining follow-up steps.

    This object does not contain any dynamic dependency information.
    It only holds initial dependencies known at the time the step is defined.

    All paths and environment variable names are stored in sorted order to ensure consistency.
    If paths are relative, they should be relative to the work directory.
    """

    command: str = attrs.field(converter=str)
    """The command executed by the step."""

    inp: list[Path] = attrs.field(converter=_convert_to_paths)
    """List of input paths of the step."""

    env: list[str] = attrs.field(converter=_convert_to_strs)
    """List of names of environment variables to which the step is sensitive."""

    out: list[Path] = attrs.field(converter=_convert_to_paths)
    """List of output paths of the step."""

    vol: list[Path] = attrs.field(converter=_convert_to_paths)
    """List of volatile output paths of the step."""

    workdir: Path = attrs.field(converter=coerce_path)
    """The work directory of the step."""

    def filter_inp(self, pattern: str, **subs: str) -> NamedGlob:
        """Return a `NamedGlob` object with matching results from `self.inp`."""
        ng = NamedGlob(pattern, subs)
        ng.extend(self.inp)
        return ng

    def filter_out(self, pattern: str, **subs: str) -> NamedGlob:
        """Return a `NamedGlob` object with matching results from `self.out`."""
        ng = NamedGlob(pattern, subs)
        ng.extend(self.out)
        return ng

    def filter_vol(self, pattern: str, **subs: str) -> NamedGlob:
        """Return a `NamedGlob` object with matching results from `self.vol`."""
        ng = NamedGlob(pattern, subs)
        ng.extend(self.vol)
        return ng

command = attrs.field(converter=str) class-attribute instance-attribute

The command executed by the step.

env = attrs.field(converter=_convert_to_strs) class-attribute instance-attribute

List of names of environment variables to which the step is sensitive.

inp = attrs.field(converter=_convert_to_paths) class-attribute instance-attribute

List of input paths of the step.

out = attrs.field(converter=_convert_to_paths) class-attribute instance-attribute

List of output paths of the step.

vol = attrs.field(converter=_convert_to_paths) class-attribute instance-attribute

List of volatile output paths of the step.

workdir = attrs.field(converter=coerce_path) class-attribute instance-attribute

The work directory of the step.

filter_inp(pattern, **subs)

Return a NamedGlob object with matching results from self.inp.

Source code in stepup/core/stepinfo.py
def filter_inp(self, pattern: str, **subs: str) -> NamedGlob:
    """Return a `NamedGlob` object with matching results from `self.inp`."""
    ng = NamedGlob(pattern, subs)
    ng.extend(self.inp)
    return ng

filter_out(pattern, **subs)

Return a NamedGlob object with matching results from self.out.

Source code in stepup/core/stepinfo.py
def filter_out(self, pattern: str, **subs: str) -> NamedGlob:
    """Return a `NamedGlob` object with matching results from `self.out`."""
    ng = NamedGlob(pattern, subs)
    ng.extend(self.out)
    return ng

filter_vol(pattern, **subs)

Return a NamedGlob object with matching results from self.vol.

Source code in stepup/core/stepinfo.py
def filter_vol(self, pattern: str, **subs: str) -> NamedGlob:
    """Return a `NamedGlob` object with matching results from `self.vol`."""
    ng = NamedGlob(pattern, subs)
    ng.extend(self.vol)
    return ng

dump_step_info(filename, step_info)

Dump one or more step info objects to a JSON file.

The file will contain a single JSON object or a JSON array of such objects.

Source code in stepup/core/stepinfo.py
def dump_step_info(filename: StrPath, step_info: StepInfo | Iterable[StepInfo]):
    """Dump one or more step info objects to a JSON file.

    The file will contain a single JSON object or a JSON array of such objects.
    """
    with open(filename, "w") as fh:
        json.dump(json_converter.unstructure(step_info), fh, indent=2)
        fh.write("\n")

load_step_info(filename)

Load one or more step info objects from a JSON file.

The file should contain a single JSON object or a JSON array of such objects.

Source code in stepup/core/stepinfo.py
def load_step_info(filename: StrPath) -> StepInfo | list[StepInfo]:
    """Load one or more step info objects from a JSON file.

    The file should contain a single JSON object or a JSON array of such objects.
    """
    with open(filename) as fh:
        data = json.load(fh)
    if isinstance(data, dict):
        return json_converter.structure(data, StepInfo)
    return json_converter.structure(data, list[StepInfo])