CPyCodeCompiler.__init__
- CPyCodeCompiler.__init__(name: str, compile_at_exit: bool, write_header_at_enter: bool, folder: str | None = None)[source]
Generate the following files:
Python file containing a binding to the generated library
C-file containing the source code for the library
The Library is the compiled C-file with the file extension *.dll on Windows or *.so on Linux
Examples
The following code generates
test_library.py,
_test_library.c,
_test_library.dll or _test_library.so
in the folder res/tests/codegen and writes an element information for the element type CPE4
>>> os.makedirs("res/tests/codegen", exist_ok=True) >>> with CPyCodeCompiler( ... "test_library", ... compile_at_exit=True, ... write_header_at_enter=True, ... folder="res/tests/codegen" ... ) as compiler: ... compiler.write_element_info("CPE4", 2, 4, 4)
The generated package can be imported.
>>> from res.tests.codegen import test_library >>> test_library.map_type_to_info["CPE4"] ElementInfo(number_of_dimensions=2, number_of_nodes=4, number_of_integration_points=4)
- Parameters:
name – File name (without extension) of the generated files
compile_at_exit – Compile C-code to a library after the end of the with statement
write_header_at_enter – Import and declare all necessary packages and attributes at the top of the Python and C-file.
folder – Folder in which the generated code and the compiled library is located