runway.variables module

Runway variables.

class runway.variables.Variable[source]

Bases: object

Represents a variable provided to a Runway directive.

__init__(name: str, value: Any, variable_type: Literal['cfngin', 'runway'] = 'cfngin') None[source]

Initialize class.

Parameters:
  • name – Name of the variable (directive/key).

  • value – The variable itself.

  • variable_type – Type of variable (cfngin|runway).

__repr__() str[source]

Return object representation.

property dependencies: set[str]

Stack names that this variable depends on.

Returns:

Stack names that this variable depends on.

Return type:

set[str]

get(key: str, default: Any = None) Any[source]

Implement evaluation of self.get.

Parameters:
  • key – Attribute name to return the value for.

  • default – Value to return if attribute is not found.

resolve(context: CfnginContext | RunwayContext, provider: Provider | None = None, variables: RunwayVariablesDefinition | None = None, **kwargs: Any) None[source]

Resolve the variable value.

Parameters:
  • context – The current context object.

  • provider – Subclass of the base provider.

  • variables – Object containing variables passed to Runway.

  • **kwargs – Arbitrary keyword arguments.

Raises:

FailedVariableLookup

property resolved: bool

Boolean for whether the Variable has been resolved.

Variables only need to be resolved if they contain lookups.

property value: Any

Return the current value of the Variable.

Raises:

UnresolvedVariable – Value accessed before it have been resolved.

class runway.variables.VariableValue[source]

Bases: object

Syntax tree base class to parse variable values.

__iter__() Iterator[Any][source]

How the object is iterated.

Raises:

NotImplementedError – Should be defined in a subclass.

__repr__() str[source]

Return object representation.

Raises:

NotImplementedError – Should be defined in a subclass.

property dependencies: set[Any]

Stack names that this variable depends on.

classmethod parse_obj(obj: _PydanticModelTypeVar, variable_type: Literal['cfngin', 'runway'] = 'cfngin') VariableValuePydanticModel[_PydanticModelTypeVar][source]
classmethod parse_obj(obj: dict[str, Any], variable_type: Literal['cfngin', 'runway'] = 'cfngin') VariableValue
classmethod parse_obj(obj: list[Any], variable_type: Literal['cfngin', 'runway'] = 'cfngin') VariableValueList
classmethod parse_obj(obj: int, variable_type: Literal['cfngin', 'runway'] = 'cfngin') VariableValueLiteral[int]
classmethod parse_obj(obj: str, variable_type: Literal['cfngin', 'runway'] = 'cfngin') VariableValueConcatenation[VariableValueLiteral[str] | VariableValueLookup]

Parse complex variable structures using type appropriate subclasses.

Parameters:
  • obj – The objected defined as the value of a variable.

  • variable_type – Type of variable (cfngin|runway).

resolve(context: CfnginContext | RunwayContext, provider: Provider | None = None, variables: RunwayVariablesDefinition | None = None, **kwargs: Any) None[source]

Resolve the variable value.

Parameters:
  • context – The current context object.

  • provider – Subclass of the base provider.

  • variables – Object containing variables passed to Runway.

  • **kwargs – Arbitrary keyword arguments.

property resolved: bool

Use to check if the variable value has been resolved.

Raises:

NotImplementedError – Should be defined in a subclass.

property simplified: Any

Return a simplified version of the value.

This can be used to concatenate two literals into one literal or flatten nested concatenations.

Should be implimented in subclasses where applicable.

property value: Any

Value of the variable. Can be resolved or unresolved.

Raises:

NotImplementedError – Should be defined in a subclass.

class runway.variables.VariableValueConcatenation[source]

Bases: Generic[_VariableValue], VariableValue

A concatenated variable values.

__delitem__(_index: int) None[source]

Delete item by index.

__getitem__(_index: int) _VariableValue[source]
__getitem__(_index: slice) list[_VariableValue]

Get item by index.

__init__(iterable: Iterable[_VariableValue], variable_type: Literal['cfngin', 'runway'] = 'cfngin') None[source]

Instantiate class.

Parameters:
  • iterable – Data to store in the iterable.

  • variable_type – Type of variable (cfngin|runway).

__iter__() Iterator[_VariableValue][source]

Object iteration.

__len__() int[source]

Length of the object.

__repr__() str[source]

Return object representation.

__setitem__(_index: int, _value: _VariableValue) None[source]
__setitem__(_index: slice, _value: list[_VariableValue]) None

Set item by index.

property dependencies: set[str]

Stack names that this variable depends on.

resolve(context: CfnginContext | RunwayContext, provider: Provider | None = None, variables: RunwayVariablesDefinition | None = None, **kwargs: Any) None[source]

Resolve the variable value.

Parameters:
  • context – The current context object.

  • provider – Subclass of the base provider.

  • variables – Object containing variables passed to Runway.

  • **kwargs – Arbitrary keyword arguments.

property resolved: bool

Use to check if the variable value has been resolved.

property simplified: VariableValue

Return a simplified version of the value.

This can be used to concatenate two literals into one literal or flatten nested concatenations.

property value: Any

Value of the variable. Can be resolved or unresolved.

Raises:

InvalidLookupConcatenation

class runway.variables.VariableValueDict[source]

Bases: VariableValue, MutableMapping[str, VariableValue]

A dict variable value.

__delitem__(_key: str) None[source]

Delete item by index.

__getitem__(_key: str) VariableValue[source]

Get item by index.

__init__(data: dict[str, Any], variable_type: Literal['cfngin', 'runway'] = 'cfngin') None[source]

Instantiate class.

Parameters:
  • data – Data to be stored in the object.

  • variable_type – Type of variable (cfngin|runway).

__iter__() Iterator[str][source]

How the object is iterated.

__len__() int[source]

Length of the object.

__repr__() str[source]

Return object representation.

__setitem__(_key: str, _value: VariableValue) None[source]

Set item by index.

property dependencies: set[str]

Stack names that this variable depends on.

resolve(context: CfnginContext | RunwayContext, provider: Provider | None = None, variables: RunwayVariablesDefinition | None = None, **kwargs: Any) None[source]

Resolve the variable value.

Parameters:
  • context – The current context object.

  • provider – Subclass of the base provider.

  • variables – Object containing variables passed to Runway.

  • **kwargs – Arbitrary keyword arguments.

property resolved: bool

Use to check if the variable value has been resolved.

property simplified: dict[str, Any]

Return a simplified version of the value.

This can be used to concatenate two literals into one literal or flatten nested concatenations.

property value: dict[str, Any]

Value of the variable. Can be resolved or unresolved.

class runway.variables.VariableValueList[source]

Bases: VariableValue, MutableSequence[VariableValue]

List variable value.

__delitem__(index: int) None[source]
__delitem__(index: slice) None

Delete item by index.

__getitem__(_index: int) VariableValue[source]
__getitem__(_index: slice) list[VariableValue]

Get item by index.

__init__(iterable: Iterable[Any], variable_type: Literal['cfngin', 'runway'] = 'cfngin') None[source]

Instantiate class.

Parameters:
  • iterable – Data to store in the iterable.

  • variable_type – Type of variable (cfngin|runway).

__iter__() Iterator[VariableValue][source]

Object iteration.

__len__() int[source]

Length of the object.

__repr__() str[source]

Object string representation.

__setitem__(_index: int, _value: VariableValue) None[source]
__setitem__(_index: slice, _value: list[VariableValue]) None

Set item by index.

property dependencies: set[str]

Stack names that this variable depends on.

insert(index: int, value: VariableValue) None[source]

Insert a value at a specific index.

resolve(context: CfnginContext | RunwayContext, provider: Provider | None = None, variables: RunwayVariablesDefinition | None = None, **kwargs: Any) None[source]

Resolve the variable value.

Parameters:
  • context – The current context object.

  • provider – Subclass of the base provider.

  • variables – Object containing variables passed to Runway.

  • **kwargs – Arbitrary keyword arguments.

property resolved: bool

Use to check if the variable value has been resolved.

property simplified: list[VariableValue]

Return a simplified version of the value.

This can be used to concatenate two literals into one literal or flatten nested concatenations.

property value: list[Any]

Value of the variable. Can be resolved or unresolved.

class runway.variables.VariableValueLiteral[source]

Bases: Generic[_LiteralValue], VariableValue

The literal value of a variable as provided.

__init__(value: _LiteralValue, variable_type: Literal['cfngin', 'runway'] = 'cfngin') None[source]

Instantiate class.

Parameters:
  • value – Data to store in the object.

  • variable_type – Type of variable (cfngin|runway).

__iter__() Iterator[Any][source]

How the object is iterated.

__repr__() str[source]

Return object representation.

property resolved: bool

Use to check if the variable value has been resolved.

The ValueLiteral will always appear as resolved because it does not “resolve” since it is the literal definition of the value.

property value: _LiteralValue

Value of the variable.

class runway.variables.VariableValueLookup[source]

Bases: VariableValue

A lookup variable value.

__init__(lookup_name: VariableValueLiteral[str], lookup_query: str | VariableValue, handler: type[LookupHandler[Any]] | None = None, variable_type: VariableTypeLiteralTypeDef = 'cfngin') None[source]

Initialize class.

Parameters:
  • lookup_name – Name of the invoked lookup.

  • lookup_query – Data portion of the lookup.

  • handler – Lookup handler that will be use to resolve the value.

  • variable_type – Type of variable (cfngin|runway).

Raises:
__iter__() Iterator[VariableValueLookup][source]

How the object is iterated.

__repr__() str[source]

Return object representation.

__str__() str[source]

Object displayed as a string.

property dependencies: set[str]

Stack names that this variable depends on.

resolve(context: CfnginContext | RunwayContext, provider: Provider | None = None, variables: RunwayVariablesDefinition | None = None, **kwargs: Any) None[source]

Resolve the variable value.

Parameters:
  • context – The current context object.

  • provider – Subclass of the base provider.

  • variables – Object containing variables passed to Runway.

  • **kwargs – Arbitrary keyword arguments.

Raises:

FailedLookup – A lookup failed for any reason.

property resolved: bool

Use to check if the variable value has been resolved.

property simplified: VariableValueLookup

Return a simplified version of the value.

This can be used to concatenate two literals into one literal or flatten nested concatenations.

property value: Any

Value of the variable. Can be resolved or unresolved.

Raises:

UnresolvedVariableValue – Value accessed before it has been resolved.

class runway.variables.VariableValuePydanticModel[source]

Bases: Generic[_PydanticModelTypeVar], VariableValue

A pydantic model variable value.

__delitem__(_key: str) None[source]

Delete item by index.

__getitem__(_key: str) VariableValue[source]

Get item by index.

__init__(data: _PydanticModelTypeVar, variable_type: Literal['cfngin', 'runway'] = 'cfngin') None[source]

Instantiate class.

Parameters:
  • data – Data to be stored in the object.

  • variable_type – Type of variable (cfngin|runway).

__iter__() Iterator[str][source]

How the object is iterated.

__len__() int[source]

Length of the object.

__repr__() str[source]

Return object representation.

__setitem__(_key: str, _value: VariableValue) None[source]

Set item by index.

property dependencies: set[str]

Stack names that this variable depends on.

resolve(context: CfnginContext | RunwayContext, provider: Provider | None = None, variables: RunwayVariablesDefinition | None = None, **kwargs: Any) None[source]

Resolve the variable value.

Parameters:
  • context – The current context object.

  • provider – Subclass of the base provider.

  • variables – Object containing variables passed to Runway.

  • **kwargs – Arbitrary keyword arguments.

property resolved: bool

Use to check if the variable value has been resolved.

property simplified: dict[str, Any]

Return a simplified version of the value.

This can be used to concatenate two literals into one literal or flatten nested concatenations.

property value: _PydanticModelTypeVar

Value of the variable. Can be resolved or unresolved.

Uses the original pydantic model class to parse the resolved data back into a pydantic model.

runway.variables.resolve_variables(variables: list[Variable], context: CfnginContext | RunwayContext, provider: Provider | None = None) None[source]

Given a list of variables, resolve all of them.

Parameters:
  • variables – List of variables.

  • context – CFNgin context.

  • provider – Subclass of the base provider.