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 byself.module
- Returns:
typing.Optional
[str
] – Pythonimport
statements needed for any enums used byself.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_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:
arguments (
collections.abc.Iterable
[typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]]) – Arguments for the callable. We get the Fortran passing steps for these.dynamic_unit (
typing.Optional
[str
]) – If provided, specifies the source of the units to which we want to convert the arguments.
- 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 appliedThe 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_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
- 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:
value (
typing.Union
[fgen.data_models.value.Value
,fgen.data_models.multi_return.MultiReturn
]) – Value for which to get the need type to importcan_be_callable_argument (
bool
) – Whether this value could be a callable’s argument
- 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 requirementsThese requirements are the requirements defined in
self.module.requirements
.- Returns:
str
– Pythonimport
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 theimport
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:
arguments (
collections.abc.Iterable
[typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
]]) – Arguments for the callablereturn_value (
typing.Union
[fgen.data_models.multi_return.MultiReturn
,fgen.data_models.value.Value
,None
]) – Return value from the callableinclude_self_argument (
bool
) – Should we assume that there is aself
argument to the callable too?
- Returns:
str
–verify_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:
bool
–True
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:
value (
typing.Union
[fgen.data_models.value.Value
,fgen.data_models.multi_return.MultiReturn
]) – Value to checkmodule (
fgen.data_models.module.Module
) – Module in which the value is being used
- Returns:
bool
–True
if this values requires an import,False
otherwise.
- property requires_quantity: bool#
Whether the module being wrapped requires
pint
’s quantity to be exposed
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:
builder (
fgen.wrapper_building.python_wrapper_module.PythonWrapperModuleBuilder
) – Builder to use to generate the Python wrapper moduleextension (
str
) – Name of the extension module that will contain the compiled wrappers
- Returns:
str
– Python wrapper module as code