Builder
BuilderLink
The sierra.core.builder
module is responsible for building invoker scripts in the Sierra Dev. It provides functionality to assemble standalone scripts from invoker definitions, handling imports, dependencies, and entry points.
Creating a builder?
sierra.core.builder
Link
ClassesLink
SierraInvokerBuilder
Link
SierraInvokerBuilder(
client: sierra_client.SierraDevelopmentClient,
)
Bases: sierra_core_base.SierraCoreObject
Builder for Sierra invoker scripts.
Generates commands, extracts and cleans imports, handles dependencies, and constructs a main entry-point with type-checked parameters.
PARAMETER | DESCRIPTION |
---|---|
client
|
The client instance containing the environment and logger.
TYPE:
|
ATTRIBUTE | DESCRIPTION |
---|---|
client |
The client instance provided during initialization.
TYPE:
|
Initialize a SierraCoreObject.
PARAMETER | DESCRIPTION |
---|---|
client
|
The Sierra development client.
TYPE:
|
Notes
Logs each initialization step via the client's logger.
AttributesLink
FunctionsLink
generate_command
Linkgenerate_command(
invoker: sierra_invoker.InvokerScript,
) -> str
Construct the CLI command to invoke the given script in the virtual environment.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The script to generate a command for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The constructed command. |
extract_imports
Linkextract_imports(
invoker: sierra_invoker.InvokerScript,
) -> list[str]
Extract all import statements from an invoker script.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The invoker script from which to extract imports.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list of str
|
A list of import statements found in the script. |
Notes
This function reads the file associated with the provided invoker and parses it to extract all import statements, including standard imports and from-import statements.
Examples:
get_filtered_imports
Linkget_filtered_imports(
invoker: sierra_invoker.InvokerScript,
) -> list[str]
Retrieve all import statements excluding those from the sierra namespace.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The invoker script from which to extract non-sierra imports.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list of str
|
A list of import statements excluding sierra namespace imports. |
Notes
This function utilizes the extract_imports
method to gather all imports
and filters out those that are related to the sierra namespace.
get_required_sierra_imports
LinkGet only the essential sierra imports needed for the standalone script.
remove_sierra_imports
Linkremove_sierra_imports(
invoker: sierra_invoker.InvokerScript,
) -> str
Strip out all imports from the 'sierra' namespace in a script.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The invoker script from which to remove sierra imports.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The source code of the invoker with all sierra imports removed. |
get_deps_source
Linkget_deps_source(
invoker: sierra_invoker.InvokerScript,
) -> list[str]
Extract the source code for each dependency function and remove any decorators.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The invoker script containing the dependencies.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list of str
|
A list of source code strings for each dependency function without decorators. |
get_entry_point_source
Linkget_entry_point_source(
invoker: sierra_invoker.InvokerScript,
) -> str
Extract and rebuild the entry point function with simple type annotations.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The invoker script containing the entry point.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The source code of the entry point function with simple type annotations. |
get_parameter_type_string
Linkget_parameter_type_string(
param: sierra_abc_sierra.SierraInvokerParam,
) -> str
Get the proper type string for a parameter including Optional wrapper.
PARAMETER | DESCRIPTION |
---|---|
param
|
The parameter to get the type string for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The type string for the parameter. |
get_arg_type_checking
Linkget_arg_type_checking(
param: sierra_abc_sierra.SierraInvokerParam,
) -> str
Generate runtime presence and type checks for a single parameter.
PARAMETER | DESCRIPTION |
---|---|
param
|
The parameter to generate type checks for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The type checking code as a single string. |
get_sys_args_parsing
Linkget_sys_args_parsing(
invoker: sierra_invoker.InvokerScript,
) -> list[str]
Generate sys.argv parsing with proper type conversion and validation.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The invoker script containing parameters for parsing.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list of str
|
A list of source code lines for argument parsing. |
create_type_safe_main
Linkcreate_type_safe_main(
invoker: sierra_invoker.InvokerScript,
) -> str
Build a type-safe main guard with comprehensive error handling.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The invoker script containing parameters for parsing.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The type-safe main guard. |
build
Linkbuild(invoker: sierra_invoker.InvokerScript) -> str
Assemble the full standalone script.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The invoker script to generate a standalone script for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The full standalone script. |
generate_file_header
Linkgenerate_file_header(
invoker: sierra_invoker.InvokerScript,
) -> str
Generate file header with metadata.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The invoker script to generate a standalone script for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The file header with metadata. |
validate_script_syntax
Link
get_metadata
Linkget_metadata(
invoker: sierra_invoker.InvokerScript,
) -> dict[str, typing.Any]
Retrieve metadata about the invoker.
PARAMETER | DESCRIPTION |
---|---|
invoker
|
The invoker script instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict of str to Any
|
Metadata dictionary containing invoker information. |