fgen.wrapping_strategies.interface#
Interface definition for wrapping strategies
WrappingStrategyLike#
- class WrappingStrategyLike(*args, **kwargs)[source]#
Bases:
Protocol
Wrapping strategy interface
- generate_python_for_fortran_return_value_processing(value, fortran_module_callable, fortran_module_callable_args, dynamic_unit)[source]#
Generate the Python code that processes the value returned from Fortran
- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Value for which to generate the Python code for processing the value returned from Fortranfortran_module_callable (
str
) – The Fortran module callable to callfortran_module_callable_args (
collections.abc.Iterable
[str
]) – The arguments to pass to the Fortran module callable (sometimes these need to be supplemented, hence we pass them separately).dynamic_unit (
typing.Optional
[str
]) – If provided, specifies where to retrieve the dynamic unit ofvalue
from.
- Returns:
str
– Python code that calls the callable and processes the results into the expected Python type.
- get_fortran_for_getter(value, class_being_wrapped, value_manager_get_free_instance_number=None, value_manager_get_instance=None)[source]#
Get the Fortran for the wrapper module’s getter.
- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Value returned from the getter.class_being_wrapped (
str
) – Derived type being wrapped.value_manager_get_free_instance_number (
typing.Optional
[str
]) – Callable which gets a free instance number for objects of the type ofvalue
.value_manager_get_instance (
typing.Optional
[str
]) – Callable which gets an instance for objects of the type ofvalue
.
- Returns:
str
– Fortran for the wrapper module’s getter.
- get_fortran_for_method_returning_wrapped_type(fortran_wrapper_module_callable, receiving_from_python_steps, return_value, class_being_wrapped, method_name, return_value_manager_get_free_instance_number, return_value_manager_get_instance)[source]#
Get the Fortran for a method which returns the wrapped type
- Parameters:
fortran_wrapper_module_callable (
str
) – The Fortran wrapper module’s callable’s namereceiving_from_python_steps (
fgen.wrapping_strategies.receiving_from_python_steps.ReceivingFromPythonSteps
) – Steps to receive the callable’s inputs from Pythonreturn_value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – The (original) Fortran module callable’s return valueclass_being_wrapped (
str
) – The name of the Fortran derived type being wrappedmethod_name (
str
) – The name of the method being wrappedreturn_value_manager_get_free_instance_number (
typing.Optional
[str
]) – Callable which gets a free instance number for objects of the type ofreturn_value
.return_value_manager_get_instance (
typing.Optional
[str
]) – Callable which gets an instance for objects of the type ofreturn_value
.
- Returns:
str
– Fortran for wrapping the method
- get_fortran_wrapper_module_getter(value)[source]#
Get the name of the getter in the Fortran wrapper module
- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Value for which to get the getter- Returns:
str
– Name of the getter in the Fortran wrapper module
- get_fortran_wrapper_module_setter(value)[source]#
Get the name of the setter in the Fortran wrapper module
- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Value for which to get the getter- Returns:
str
– Name of the getter in the Fortran wrapper module
- get_fortran_wrapper_statement_declarations_for_returning_method_result_to_python(method, prefix)[source]#
Get statement declarations for the returning a method’s result to Python
- Parameters:
method (
fgen.data_models.method.Method
) – Method for which to get the statement declarations.prefix (
str
) – Prefix to use when naming the method in Fortran.
- Returns:
list
[str
] – Statement declarations for the returning a method’s result to Python.
- get_fortran_wrapper_statement_declarations_getters_and_setters(value)[source]#
Get statement declarations for the getters/setters in the Fortran wrapper module
- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Value for which to get the statement declarations- Returns:
list
[str
] – Statement declarations for the getters and setters in the Fortran wrapper module.
- get_passing_to_fortran_steps(value, dynamic_unit)[source]#
Get the steps required to pass this value to the Fortran
- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Value to pass into Fortrandynamic_unit (
typing.Optional
[str
]) – If provided, specifies the dynamic units to convert values to.
- Returns:
fgen.wrapping_strategies.passing_to_fortran_steps.PassingToFortranSteps
– Steps required to pass the value into the Fortran
- get_python_argument_declaration_type_annotation(value)[source]#
Get the type annotation to use in Python user-facing declarations
- Parameters:
value (
fgen.data_models.value.Value
) – Value for which to get the type annotation- Returns:
str
– Type annotation to use in the Python argument declaration
- get_python_getter_docstring(value)[source]#
Get docstring for the Python getter for the value
- Parameters:
value (
fgen.data_models.value.Value
) – Value for which to get the Python getter docstring- Returns:
str
– Python getter docstring
- get_python_post_verify_units_input_type_annotation(value)[source]#
Get input type annotation, assuming the
verify_units
decorator is applied.The type annotation is for when
value
is used as an input to a Python callable.- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Value for which to get the type annotation- Returns:
str
– Type annotation for the value, assuming theverify_units
decorator is applied.
- get_python_return_type_annotation(value)[source]#
Get the return type annotation for the Python attribute
- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Value for which to get the return type annotation for the Python attribute- Returns:
str
– Return type annotation for the Python attribute
- get_python_setter_docstring(value)[source]#
Get docstring for the Python setter for the value
- Parameters:
value (
fgen.data_models.value.Value
) – Value for which to get the Python setter docstring- Returns:
str
– Python setter docstring
- get_python_user_facing_name(value)[source]#
Get the name that Python users will use for this value
For example, when naming attributes or using this value as an argument in a function/method.
- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Name that Python users will use for this value- Returns:
str
– Name to use for the Python attribute
- get_receiving_from_python_steps(value, dynamic_unit=None, providing_module=None, get_instance_callable_name=None)[source]#
Get the steps required to receive the value from Python
- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Value to receive from Pythondynamic_unit (
typing.Optional
[str
]) – The source of the dynamic unit, if this value has one.providing_module (
typing.Optional
[fgen.data_models.module.Module
]) – The value that providesvalue
’s type, if it is not intrinsic.get_instance_callable_name (
typing.Optional
[str
]) – The name of the callable used to get instances of wrapped derived types (typically comes fromfgen.wrapper_building.fortran_wrapper_module.FortranWrapperModuleBuilder.shared
).
- Returns:
fgen.wrapping_strategies.receiving_from_python_steps.ReceivingFromPythonSteps
– Steps required to receive the value from Python
- get_type_attribute_declaration_for_value_to_pass_to_original_fortran_module(value)[source]#
Get the type attribute declaration for the value used to pass information to the original Fortran module
This is not always the same as the type used by the original Fortran module, particularly when allocatable types are involved.
For the definition of a type attribute declaration, see
fgen.fortran_parsing
.- Parameters:
value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]) – Value for which to get the type attribute declaration for the value to pass to the original Fortran.- Returns:
str
– Type attribute declaration for the value to use to passvalue
to the original Fortran.