Flow123d  JB_transport-9331eee
Public Member Functions | Static Public Member Functions | List of all members
PythonLoader Class Reference

#include <python_loader.hh>

Public Member Functions

 TYPEDEF_ERR_INFO (EI_PythonMessage, std::string)
 
 DECLARE_EXCEPTION (ExcPythonError,<< "Python Error: "<< EI_PythonMessage::val<< "\n")
 

Static Public Member Functions

static void initialize ()
 
static pybind11::module_ load_module_from_file (const std::string &fname)
 
static pybind11::module_ load_module_from_string (const std::string &module_name, const std::string &func_name, const std::string &source_string)
 
static pybind11::module_ load_module_by_name (const std::string &module_name)
 
static void throw_error (const pybind11::error_already_set &ex)
 
static void add_sys_path (const std::string &path)
 
static std::vector< std::string > get_python_path ()
 

Detailed Description

Class with static only members, should be used to load and compile Python sources either from file or from string. Implement correct initialization and finalization. TODO:

Definition at line 75 of file python_loader.hh.

Member Function Documentation

◆ add_sys_path()

void PythonLoader::add_sys_path ( const std::string &  path)
static

Add path to python sys_path.

Definition at line 148 of file python_loader.cc.

Here is the caller graph for this function:

◆ DECLARE_EXCEPTION()

PythonLoader::DECLARE_EXCEPTION ( ExcPythonError  ,
<< "Python Error: "<< EI_PythonMessage::val<< "\n"   
)

◆ get_python_path()

std::vector< std::string > PythonLoader::get_python_path ( )
static

Returns vector of Python paths.

Definition at line 165 of file python_loader.cc.

Here is the caller graph for this function:

◆ initialize()

void PythonLoader::initialize ( )
static

Calls python initialization and guarantee that appropriate finalization will be called. Do nothing if initialization was done.

The method with no parameters is called at the beginning of every function of this class, so an explicit call to it has only sense if one would like to provide alternative python home directories. The string has form <prefix>[:<exec_prefix>] where <prefix> is prefix for platform independent libraries (namely sources of python standard libraries) and <exec_prefix> is prefix for platform dependent libraries namely for the python executable.

Definition at line 35 of file python_loader.cc.

Here is the caller graph for this function:

◆ load_module_by_name()

py::module_ PythonLoader::load_module_by_name ( const std::string &  module_name)
static

Method which loads module by given module_name module_name can (and probably will) contain packages path (will contain dots '.' which detonates package)

Example: PyObject * python_module = PythonLoader::load_module_by_name ("profiler.profiler_formatter_module")

will import module 'profiler_formatter_module' from package 'profiler'

Definition at line 78 of file python_loader.cc.

Here is the caller graph for this function:

◆ load_module_from_file()

py::module_ PythonLoader::load_module_from_file ( const std::string &  fname)
static

This function loads a module from the given file. Resulting module has to be deallocated by Py_DECREF() macro.

Definition at line 41 of file python_loader.cc.

Here is the caller graph for this function:

◆ load_module_from_string()

py::module_ PythonLoader::load_module_from_string ( const std::string &  module_name,
const std::string &  func_name,
const std::string &  source_string 
)
static

This function compile code in the given string and creates a module with name module_name. Module contains one function with name func_name. Function must be defined in source_strimg. Resulting module has to be deallocated by Py_DECREF() macro.

Definition at line 62 of file python_loader.cc.

◆ throw_error()

void PythonLoader::throw_error ( const pybind11::error_already_set &  ex)
static

Formats and throws ExcPythonError exception.

Definition at line 93 of file python_loader.cc.

Here is the caller graph for this function:

◆ TYPEDEF_ERR_INFO()

PythonLoader::TYPEDEF_ERR_INFO ( EI_PythonMessage  ,
std::string   
)

Definition of exception thrown by python compiler or interpreter.


The documentation for this class was generated from the following files: