class documentation

Represents a target with an item to create, its dependencies, how to compute its state (hashed content, fingerprint), how to (re-)create it and an optional nice name.

Method __init__ Creates a new Target.
Method __str__ Readable short form for a Target
Method showNameOnly Suggest to tools like toGraphviz not to show a string representation of the item, but instead only use the name. If no explicit name was provided, calling this function is silly, as in that case the name is ...
Instance Variable cmd Function to (re-)create the target.
Instance Variable dependencies The target's dependencies.
Instance Variable force If set to True before the build starts, the target is assumed to be out-of-date, independent of the computed state hash. This can be used to force rebuilding a target.
Instance Variable item The item of the target, often a file or directory path.
Instance Variable name The target's name, defaulting to str(item).
Instance Variable nameOnly Setting this to True means that a representation of the item should typically not be shown in output. Currently used only when the dependency graph is drawn.
Instance Variable recreated Set during updateTargets if this target was out-of-date and its command was run.
Instance Variable started Set during updateTargets as soon as this target is considered for updating.
Instance Variable stateGenerator State generator for the target.
Instance Variable updated Set during updateTargets as soon as all dependencies are done.
def __init__(self, item: T, *dependencies: Target[Any], state: str | Callable[[T], str] | None = None, name: str | None = None, cmd: Callable[Concatenate[T, ...], None] | None = None):

Creates a new Target.

An "input target", for example a source code directory, may be created with just an item, as it has no dependencies, the state generator is derived automatically, because it is an existing directory, and nothing needs to be done, so it has no command.

Parameters
item:Trepresents the item to keep up-to-date, like a file or directory name
*dependencies:Target[Any]the dependencies of this target
state:str | Callable[[T], str] | None

describes how to generate a state (checksum, fingerprint) for this target's item. The function must generate a small fingerprint string from the target's item.

If state is not provided, the item must denote an existing file or directory for a default of stateFileContent or stateDirContent, or implement StateProvider, in which case the item's StateProvider.provideState function is used to generate its state.

If given as a string, it must be "dir", "file", "new", "fixed" or "value" for stateDirContent, stateFileContent, stateNew, stateFixed or stateValue respectively.

Otherwise it must be a function with parameter T to be called with the Target's item to create the checksum.

name:str | NoneA nice name for the target to use, for example, on the command line. The default is name is str(item).
cmd:Callable[Concatenate[T, ...], None] | Nonethe command to run to (re-)create the target. Its parameters will be the target's item as well as the items of all dependencies.
def __str__(self) -> str:

Readable short form for a Target

def showNameOnly(self) -> Self:

Suggest to tools like toGraphviz not to show a string representation of the item, but instead only use the name. If no explicit name was provided, calling this function is silly, as in that case the name is str(item) anyway.

This is typically used for targets whose string representation reveals a developers local setup, like environment variables. If the representation ends up committed, like the dependency graph, targets which change frequently, like file names containing a version, may also opt to use showNameOnly().

cmd: Final[Callable[Concatenate[T, ...], None] | None] =

Function to (re-)create the target.

dependencies: Final[tuple[Target[Any], ...]] =

The target's dependencies.

force: bool =

If set to True before the build starts, the target is assumed to be out-of-date, independent of the computed state hash. This can be used to force rebuilding a target.

item: Final[T] =

The item of the target, often a file or directory path.

name: Final[str] =

The target's name, defaulting to str(item).

It can be used as parameter for updateTargets.

nameOnly: bool =

Setting this to True means that a representation of the item should typically not be shown in output. Currently used only when the dependency graph is drawn.

recreated: bool =

Set during updateTargets if this target was out-of-date and its command was run.

This does not say whether the target was actually changed by running its cmd, it merely informs that the command was run.

started: bool =

Set during updateTargets as soon as this target is considered for updating.

stateGenerator: Final[StateProvider] =

State generator for the target.

updated: bool =

Set during updateTargets as soon as all dependencies are done.

The target's command may or may not be run subsequently.