targets.script_params
import targets.script_params
class targets.script_params.Decl(
decl_type,
arg_validator,
input_type,
default,
required,
name,
output,
desc,
values,
advanced,
fn,
allow_empty=False,
explicit_default=False,
extra_data={},
telemetry=False
)
Declaration of a single script parameter.
It is a leaf in the declaration tree and holds what the target script says about the parameter, not its value; values are kept in targets.script_params.Param objects.
name: parameter name, without namespace prefix.type: Python type of the value, e.g. int or str.input_type: type as written in the script, e.g. "u8" or "list[int]".validate: function that checks a value and converts it to the right form, or raises ValueError.default: default value, or None.explicit_default: true if the script gave a default value.required: true if the parameter must be given a value.output: true if the script sets the value itself; such parameters are never required.description: help text for the parameter.values: list of allowed values, or empty if any value is allowed.advanced: integer level; higher means more advanced.allow_empty: true if None (NIL) is a valid value.provided: true if an importing script promised to set the value, using provides.fn: file name of the script where the parameter was declared or where its default was last changed.extra_data: dict with all x- keys from the declaration.telemetry: true if the value may be reported in telemetry.targets.script_params.dump_declarations(
decls: Dict[str, Union[targets.script_params.Decl, Dict]],
advanced: Optional[int],
prune=True
) -> Dict
Return a dump tree of the declaration tree decls.
The tree has the output of dump for each targets.script_params.Decl leaf node.
targets.script_params.dump_parameters(
decls: Dict[str, Union[targets.script_params.Decl, Dict]],
tree: Dict[str, Union[targets.script_params.Param, Dict]],
include_unassigned=True
) -> Dict
Return a dump tree of the argument tree tree.
The tree matches the declaration tree decls and has the output of dump for each targets.script_params.Param leaf node. For unassigned parameters a similar dump structure is added.
targets.script_params.init()
Initialise script parameter functionality.
class targets.script_params.Param(name, value, state, decl=None, fn=None)
Value of a single script parameter.
It is a leaf in the argument tree. The declaration is kept in a targets.script_params.Decl object.
name: parameter name, without namespace prefix.value: the value, or for a reference the name of, or the Param object for, the referenced parameter. Use get_value to get the final value.state: "user" if set by the user, "script" if set by the script code, otherwise "default".decl: the matching targets.script_params.Decl, or None.fn: file name of the script where the value was set, or "<cmdline>".is_ref: true if the value refers to another parameter (written as ^name).targets.script_params.parse_script(
fn: Union[pathlib.Path, str],
lookup: Callable[[str], str],
targets: list,
cmdline_args: Dict[str, Union[targets.script_params.Param, Dict]] = None,
ignore_blueprints: bool = False
) -> Optional[Dict]
Parse the script file or string fn and return its meta-data.
This is the script parser entry point. The lookup function is used on all file references (import/script/target).
A dict with the keys code, params, args, desc and blueprints. The value of code is None if the script has no code.
TargetParamError if fn is not a valid script.
targets.script_params.resolve_parameters(
fn: pathlib.Path,
decls: Dict[str, Union[targets.script_params.Decl, Dict]],
args: Dict[str, Union[targets.script_params.Param, Dict]],
errors: dict,
lookup_file: Callable[[str], str],
logger: Callable[[str], NoneType],
roots: Optional[Dict] = None,
prefix=''
) -> Dict[str, Union[targets.script_params.Param, Dict]]
Resolve arguments args against the declaration tree decls.
Assigned values are removed from args. Errors, such as an invalid type or a missing value for a required parameter, are added to the dict errors, with the flat parameter name as key.
The argument tree for the script fn.
targets.script_params.save_parameters(
tree: Dict[str, Union[targets.script_params.Param, Dict]],
user_only=True,
resolve_refs=True
) -> Dict
Return a tree of argument values from the argument tree tree.
By default, only arguments that were set explicitly by the user are included.
targets.script_params.write_parameters(
args: Dict,
script: str,
f: <class 'TextIO'>
)
Write a preset file to f.
The preset has the arguments args and the target pointer script.
targets.script_params.write_yaml(
data: Dict,
output_file: <class 'TextIO'>
) -> Optional[str]
Encode data as YAML and write it to the stream output_file.
The YAML text if output_file is None, otherwise None.