fgen.wrapper_building.python_wrapper_module

Contents

fgen.wrapper_building.python_wrapper_module#

Generation of the Python wrapper module

PythonWrapperModuleBuilder#

class PythonWrapperModuleBuilder(package, module, shared)[source]#

Bases: object

Builder of a Python wrapper module

get_enum_python_import_statements()[source]#

Get the Python import statements needed for enums used by self.module

Returns:

typing.Optional[str] – Python import statements needed for any enums used by self.module. If no imports are required for enums, None is returned.

get_fortran_wrapper_method(method)[source]#

Get the name of the method in the Fotran wrapper

Parameters:

method (fgen.data_models.method.Method) – Method for which to get the name

Returns:

str – Name of the method in the Fortran wrapper

get_module_imports(extension)[source]#

Get the module’s imports

Parameters:

extension (str) – The name of the overall extension module being built

Returns:

str – Module import statements

get_module_level_docstring()[source]#

Get the module-level docstring

Returns:

str – Module-level docstring

get_module_units()[source]#

Get the module’s units declaration

Returns:

str – Module’s units declaration

get_passing_to_fortran_steps(arguments, dynamic_unit=None)[source]#

Get passing to Fortran steps for a set of arguments

Parameters:
Returns:

fgen.wrapping_strategies.passing_to_fortran_steps.PassingToFortranSteps – Steps for passing the arguments to Fortran

get_post_verify_units_argument_list(arguments)[source]#

Get argument list to be used, assuming the verify_units decorator is applied

The argument list includes the type hints that are expected. These type hints are created on the assumption that the verify_units is being used on the callable.

Parameters:

arguments (collections.abc.Iterable[typing.Union[fgen.data_models.multi_return.MultiReturn, fgen.data_models.value.Value]]) – Arguments for which to generate the arguments list.

Returns:

str – Arguments list, in the form “argument: type,narg: type_argn…”

get_provided_type_class_methods(class_name)[source]#

Get the provided type’s class methods

Parameters:

class_name (str) – Name of the class for which we are getting the class methods.

Returns:

str – Class methods

get_provided_type_docstring()[source]#

Get the provided type’s docstring

Returns:

str – Provided type’s docstring

get_provided_type_getters_and_setters(include_setters=True)[source]#

Get the provided type’s getters and setters

Parameters:

include_setters (bool) – Should the setters be created too?

Returns:

str – Provided type’s getters and setters

get_provided_type_methods()[source]#

Get the provided type’s methods

Returns:

str – Provided type’s methods

get_provided_type_repr_methods()[source]#

Get the provided type’s representation relevant methods

Returns:

str – Representation-relevant methods for the provided type

static get_python_base_type_and_needed_types(value, can_be_callable_argument)[source]#

Get the base type and the type we need to import

Parameters:
Returns:

tuple[str, tuple[str, ...]] – Tuple. First element is the base type. The second type is the types that need to be imported.

get_python_user_facing_name(value)[source]#

Get the Python-user facing name of a value

Parameters:

value (typing.Union[fgen.data_models.multi_return.MultiReturn, fgen.data_models.value.Value]) – Value for which to get the Python user-facing name

Returns:

str – Python user-facing name

get_requirements_python_import_statements()[source]#

Get the Python import statements needed for the module’s requirements

These requirements are the requirements defined in self.module.requirements.

Returns:

str – Python import statements needed for the module

get_requirements_python_imports(module)[source]#

Get the Python imports needed for the module’s requirements

These requirements are the requirements defined in self.module.requirements.

Parameters:

module (fgen.data_models.module.Module) – Module for which to get the import statements

Returns:

dict[str, list[str]] – Modules (keys) and the types to import from them (values)

get_verify_units_decorator(arguments, return_value=None, include_self_argument=True)[source]#

Get the verify_units decorator for a callable

Parameters:
Returns:

strverify_units decorator for the callable

get_wrapping_strategy(value)[source]#

Get wrapping strategy

Parameters:

value (typing.Union[fgen.data_models.multi_return.MultiReturn, fgen.data_models.value.Value]) – Value for which to get the wrapping strategy

Returns:

fgen.wrapping_strategies.interface.WrappingStrategyLike – Wrapping strategy to use with the value

include_in_python_callable_arguments(value)[source]#

Determine whether a value should be included as an argument to Python callables

Parameters:

value (typing.Union[fgen.data_models.multi_return.MultiReturn, fgen.data_models.value.Value]) – Value to check

Returns:

boolTrue if the value should be included as an argument to Python callables, False otherwise.

module: fgen.data_models.module.Module#

Module for which to build the wrapper

package: fgen.data_models.package.Package#

Package for which the builder is building wrappers

requires_import(value, module)[source]#

Return whether a value requires an import or not

Parameters:
Returns:

boolTrue if this values requires an import, False otherwise.

property requires_np: bool#

Whether the module being wrapped requires numpy as np

property requires_npt: bool#

Whether the module being wrapped requires numpy.typing as npt

property requires_quantity: bool#

Whether the module being wrapped requires pint’s quantity to be exposed

property requires_union: bool#

Whether the module being wrapped requires typing.Union

shared: fgen.data_models.package_shared_elements.PackageSharedElements#

Elements which have to be shared across the package

For example, the names of functions which are used in more than one wrapper module.

generate_python_wrapper_module#

generate_python_wrapper_module(builder, extension)[source]#

Generate the Python wrapper module

Parameters:
Returns:

str – Python wrapper module as code