Utility
- utility.arithmetic.evaluate_simple_arithmetic_expression(expression_string: str)[source]
Evaluate a simple arithmetic expression of the form ‘x{+,-}y’
- Parameters:
- expression_stringstr
the expression to be evaluated
- Returns:
- the result of the evaluated expression string
- class utility.code.ExtraCodeFunctionMixin[source]
Bases:
object
A mixin class for providing the functionality to compile and evaluate a function and an additional, optional code fragment within a separate global environment.
Methods
evaluate_function
(function, extra_code)Compile and evaluate the given function and an additional, optional code fragment within a separate global environment and return the executable function object.
- evaluate_function(function: Callable | str, extra_code: str | None) tuple[Callable, dict[str, Any]] [source]
Compile and evaluate the given function and an additional, optional code fragment within a separate global environment and return the executable function object.
- Parameters:
- functionUnion[Callable, str]
The name of the function or a function object.
- extra_codeOptional[str]
This can contain additional code for the function definition, such as the definition of a function with multiple statements or split into multiple functions for readibility, i.e. every use case where a single simple python statement doesn’t suffice.
- Returns:
- Callable
The resulting function object.
- dict[str, Any]
The runtime environment of the function.
- utility.code.compile_and_evaluate_function_definition(source: str, function_name: str, global_environment: dict[str, Any]) tuple[Callable, dict[str, Any]] [source]
Evaluate the sequence of code statements in the given source and return the function object bound to the specified function_name name.
- Parameters:
- sourcestr
The source code of the code snippet to compile and evaluate.
- function_namestr
The name of the function to return.
- global_envdict
The global runtime environment to evaluate the given code in.
- Returns:
- Callable
The resulting function object.
- dict
The runtime environment of the function.
- Raises:
- SyntaxError
If the supplied source code has a syntax error.
- ValueError
If the supplied source code contains null bytes.
- utility.filesystem.check_directory_access_permissions(target_directory: str)[source]
Check whether writing to the specified directory is permitted. If the directory doesn’t exist, try creating it.