example_fgen_basic.runtime_helpers#
Runtime helpers
These would be moved to fgen-runtime or a similar package
Classes:
| Name | Description |
|---|---|
FinalisableWrapperBase |
Base class for Fortran derived type wrappers |
Functions:
| Name | Description |
|---|---|
add_attribute_row |
Add a row for displaying an attribute's value to a list of rows |
check_initialised |
Check that the wrapper object has been initialised before executing the method |
get_attribute_str_value |
Get the string version of an attribute's value |
to_html |
Convert an instance to its html representation |
to_pretty |
Pretty-print an instance |
to_str |
Convert an instance to its string representation |
Attributes:
| Name | Type | Description |
|---|---|---|
INVALID_INSTANCE_INDEX |
int
|
Value used to denote an invalid |
INVALID_INSTANCE_INDEX
module-attribute
#
INVALID_INSTANCE_INDEX: int = -1
Value used to denote an invalid instance_index.
This can occur value when a wrapper class has not yet been initialised (connected to a Fortran instance).
FinalisableWrapperBase #
Bases: ABC
Base class for Fortran derived type wrappers
Methods:
| Name | Description |
|---|---|
__str__ |
Get string representation of self |
Attributes:
| Name | Type | Description |
|---|---|---|
exposed_attributes |
tuple[str, ...]
|
Attributes exposed by this wrapper |
initialized |
bool
|
Is the instance initialised, i.e. connected to a Fortran instance? |
instance_index |
int
|
Model index of wrapper Fortran instance |
Source code in src/example_fgen_basic/runtime_helpers.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
exposed_attributes
abstractmethod
property
#
Attributes exposed by this wrapper
initialized
property
#
initialized: bool
Is the instance initialised, i.e. connected to a Fortran instance?
instance_index
class-attribute
instance-attribute
#
instance_index: int = field(
validator=instance_of(int),
default=INVALID_INSTANCE_INDEX,
)
Model index of wrapper Fortran instance
add_attribute_row #
add_attribute_row(
attribute_name: str,
attribute_value: str,
attribute_rows: list[str],
) -> list[str]
Add a row for displaying an attribute's value to a list of rows
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attribute_name
|
str
|
Attribute's name |
required |
attribute_value
|
str
|
Attribute's value |
required |
attribute_rows
|
list[str]
|
Existing attribute rows |
required |
Returns:
| Type | Description |
|---|---|
Attribute rows, with the new row appended
|
|
Source code in src/example_fgen_basic/runtime_helpers.py
check_initialised #
check_initialised(
method: Callable[Concatenate[Wrapper, P], T],
) -> Callable[Concatenate[Wrapper, P], T]
Check that the wrapper object has been initialised before executing the method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Callable[Concatenate[Wrapper, P], T]
|
Method to wrap |
required |
Returns:
| Type | Description |
|---|---|
Callable[Concatenate[Wrapper, P], T]
|
Wrapped method |
Raises:
| Type | Description |
|---|---|
InitialisationError
|
Wrapper is not initialised |
Source code in src/example_fgen_basic/runtime_helpers.py
get_attribute_str_value #
get_attribute_str_value(
instance: FinalisableWrapperBase, attribute: str
) -> str
Get the string version of an attribute's value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
FinalisableWrapperBase
|
Instance from which to get the attribute |
required |
attribute
|
str
|
Attribute for which to get the value |
required |
Returns:
| Type | Description |
|---|---|
String version of the attribute's value, with graceful handling of errors.
|
|
Source code in src/example_fgen_basic/runtime_helpers.py
to_html #
to_html(
instance: FinalisableWrapperBase,
exposed_attributes: Iterable[str],
) -> str
Convert an instance to its html representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
FinalisableWrapperBase
|
Instance to convert |
required |
exposed_attributes
|
Iterable[str]
|
Attributes from Fortran that the instance exposes |
required |
Returns:
| Type | Description |
|---|---|
HTML representation of the instance
|
|
Source code in src/example_fgen_basic/runtime_helpers.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
to_pretty #
to_pretty(
instance: FinalisableWrapperBase,
exposed_attributes: Iterable[str],
p: Any,
cycle: bool,
indent: int = 4,
) -> None
Pretty-print an instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
FinalisableWrapperBase
|
Instance to convert |
required |
exposed_attributes
|
Iterable[str]
|
Attributes from Fortran that the instance exposes |
required |
p
|
Any
|
Pretty printing object |
required |
cycle
|
bool
|
Whether the pretty printer has detected a cycle or not. |
required |
indent
|
int
|
Indent to apply to the pretty printing group |
4
|
Source code in src/example_fgen_basic/runtime_helpers.py
to_str #
to_str(
instance: FinalisableWrapperBase,
exposed_attributes: Iterable[str],
) -> str
Convert an instance to its string representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
FinalisableWrapperBase
|
Instance to convert |
required |
exposed_attributes
|
Iterable[str]
|
Attributes from Fortran that the instance exposes |
required |
Returns:
| Type | Description |
|---|---|
String representation of the instance
|
|