Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Enumerations | Functions | Variables
pybindings.cpp File Reference
#include "shambase/exception.hpp"
#include "shambase/print.hpp"
#include "shambase/string.hpp"
#include "shambindings/pybindaliases.hpp"
#include "shamcmdopt/tty.hpp"
#include <pybind11/eval.h>
#include <pybind11/iostream.h>
#include <pybind11/pybind11.h>
#include <string_view>
#include <exception>
#include <memory>
#include <stdexcept>
+ Include dependency graph for pybindings.cpp:

Go to the source code of this file.

Enumerations

enum  { None = 0 , Lib = 1 , Embed = 2 }
 

Functions

void py_func_printer_normal (std::string_view s)
 With pybind we print using python out stream.
 
void py_func_printer_ln (std::string_view s)
 With pybind we print using python out stream.
 
void py_func_flush_func ()
 Python print performs already a flush so we need nothing here.
 
void register_pybind_init_func (fct_sig fct)
 Add a python module init function to the init list.
 
void register_py_to_sham_print (py::module &m)
 
template<bool is_lib_mode>
void shambindings::init (py::module &m)
 
void shambindings::init_lib (py::module &m)
 Init python bindings and register them to Python API.
 
void shambindings::init_embed (py::module &m, bool hook_stdout=true)
 Init python bindings and register them to Python API.
 
void shambindings::expect_init_lib (SourceLocation loc=SourceLocation{})
 Expect python bindings to be initialized as lib mode, throws if not.
 
void shambindings::expect_init_embed (SourceLocation loc=SourceLocation{})
 Expect python bindings to be initialized as embed mode, throws if not.
 

Variables

std::unique_ptr< std::vector< fct_sig > > static_init_shamrock_pybind
 Statically initialized python module init function list We use a unique pointer to ensure that the vector is not reinitialized during program init which would empty the function list otherwise.
 
enum shambindings:: { ... }  shambindings::init_state = None
 

Detailed Description

Author
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

Definition in file pybindings.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Definition at line 121 of file pybindings.cpp.

Function Documentation

◆ expect_init_embed()

void shambindings::expect_init_embed ( SourceLocation  loc = SourceLocation{})

Expect python bindings to be initialized as embed mode, throws if not.

Definition at line 166 of file pybindings.cpp.

+ Here is the call graph for this function:

◆ expect_init_lib()

void shambindings::expect_init_lib ( SourceLocation  loc = SourceLocation{})

Expect python bindings to be initialized as lib mode, throws if not.

Definition at line 156 of file pybindings.cpp.

+ Here is the call graph for this function:

◆ init()

template<bool is_lib_mode>
void shambindings::init ( py::module &  m)

Definition at line 124 of file pybindings.cpp.

◆ init_embed()

void shambindings::init_embed ( py::module &  m,
bool  hook_stdout = true 
)

Init python bindings and register them to Python API.

Parameters
mthe python module to bind definitions on
hook_stdoutif true, sys.stdout and sys.stderr will be hooked

Definition at line 148 of file pybindings.cpp.

+ Here is the call graph for this function:

◆ init_lib()

void shambindings::init_lib ( py::module &  m)

Init python bindings and register them to Python API.

Parameters
mthe python module to bind definitions on

Definition at line 146 of file pybindings.cpp.

+ Here is the call graph for this function:

◆ py_func_flush_func()

void py_func_flush_func ( )

Python print performs already a flush so we need nothing here.

Definition at line 46 of file pybindings.cpp.

◆ py_func_printer_ln()

void py_func_printer_ln ( std::string_view  s)

With pybind we print using python out stream.

Definition at line 40 of file pybindings.cpp.

◆ py_func_printer_normal()

void py_func_printer_normal ( std::string_view  s)

With pybind we print using python out stream.

Definition at line 34 of file pybindings.cpp.

◆ register_py_to_sham_print()

void register_py_to_sham_print ( py::module &  m)

Definition at line 67 of file pybindings.cpp.

◆ register_pybind_init_func()

void register_pybind_init_func ( fct_sig  fct)

Add a python module init function to the init list.

Register a python module init function to be ran on init.

Definition at line 59 of file pybindings.cpp.

Variable Documentation

◆ static_init_shamrock_pybind

std::unique_ptr<std::vector<fct_sig> > static_init_shamrock_pybind

Statically initialized python module init function list We use a unique pointer to ensure that the vector is not reinitialized during program init which would empty the function list otherwise.

This behavior was observed when building shamrock using object libraries using the unique_ptr fixes it

Definition at line 56 of file pybindings.cpp.