Flow123d  DF_patch_fe_data_tables-398e8e7
Classes | Namespaces | Functions
python_loader.hh File Reference


More...

#include "global_defs.h"
#include "system/exceptions.hh"
#include <string>
#include <pybind11/embed.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  internal::PythonRunning
 

Namespaces

 internal
 

Functions

class __attribute__ ((visibility("default"))) PythonLoader
 

Detailed Description


 * Copyright (C) 2015 Technical University of Liberec. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Definition in file python_loader.hh.

Function Documentation

◆ __attribute__()

class __attribute__ ( (visibility("default"))  )

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:

  • check validity of results and throw exceptions
  • better loading of modules from files
  • explain and resolve RuntimeWarning: "flow123d_python_loader:1: RuntimeWarning: Parent module 'field_python_script' not found while handling absolute import" that appears during field_python_test.cpp

Definition of exception thrown by python compiler or interpreter.

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.

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

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.

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'

Formats and throws ExcPythonError exception.

Add path to python sys_path.

Returns vector of Python paths.

Definition at line 1 of file python_loader.hh.