Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Functions | Variables
start_python.cpp File Reference
#include "shambase/popen.hpp"
#include "shambase/print.hpp"
#include "shambindings/locate_pylib.hpp"
#include "shambindings/pybindaliases.hpp"
#include "shambindings/pybindings.hpp"
#include "shambindings/start_python.hpp"
#include <pybind11/embed.h>
#include <pybind11/stl.h>
#include <cstdlib>
#include <optional>
#include <string>
+ Include dependency graph for start_python.cpp:

Go to the source code of this file.

Functions

const char * configure_time_py_sys_path ()
 path of the script to generate sys.path
 
const char * configure_time_py_executable ()
 path of the python executable that was used to configure sys.path
 
const char * run_ipython_src ()
 Script to run ipython.
 
std::string get_pypath ()
 Retrieves the Python path to be used for the application.
 
void shambindings::setpypath (std::string path)
 set the value of sys.path before init
 
void shambindings::setpypath_from_binary (std::string binary_path)
 set the value of sys.path before init from the supplied binary
 
void shambindings::modify_py_sys_path (bool do_print)
 Modify Python sys.path to point to one detected during cmake invocation.
 
void shambindings::set_sys_argv (int argc, char *argv[])
 set the value of sys.argv
 
void shambindings::start_ipython (bool do_print, int argc, char *argv[])
 Start shamrock embded ipython interpreter.
 
void shambindings::run_py_file (std::string file_path, bool do_print, int argc, char *argv[])
 run python runscript
 

Variables

std::optional< std::string > runtime_set_pypath = std::nullopt
 value use to set the value of sys.path if set by the user at runtime
 
std::string check_python_is_excpeted_version
 Script to check that the python distrib is the expected one.
 

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 start_python.cpp.

Function Documentation

◆ configure_time_py_sys_path()

const char * configure_time_py_sys_path ( )
extern

path of the script to generate sys.path

Returns
const char*

◆ get_pypath()

std::string get_pypath ( )

Retrieves the Python path to be used for the application.

This function returns the Python path that should be used, prioritizing the runtime-set value if available. If no runtime value is set, it defaults to the path configured during the application's build time.

Returns
std::string The Python path to be used.

Definition at line 57 of file start_python.cpp.

+ Here is the call graph for this function:

◆ modify_py_sys_path()

void shambindings::modify_py_sys_path ( bool  do_print)

Modify Python sys.path to point to one detected during cmake invocation.

This function will throw if bindings were not initialized in embed mode

Definition at line 96 of file start_python.cpp.

+ Here is the call graph for this function:

◆ run_py_file()

void shambindings::run_py_file ( std::string  file_path,
bool  do_print,
int  argc,
char *  argv[] 
)

run python runscript

This function will throw if bindings were not initialized in embed mode

Parameters
do_printprint log at python startup
file_pathpath to the runscript

Definition at line 142 of file start_python.cpp.

+ Here is the call graph for this function:

◆ set_sys_argv()

void shambindings::set_sys_argv ( int  argc,
char *  argv[] 
)

set the value of sys.argv

This function will throw if bindings were not initialized in embed mode

Definition at line 118 of file start_python.cpp.

+ Here is the call graph for this function:

◆ setpypath()

void shambindings::setpypath ( std::string  path)

set the value of sys.path before init

This function will throw if bindings were not initialized in embed mode

Definition at line 88 of file start_python.cpp.

+ Here is the call graph for this function:

◆ setpypath_from_binary()

void shambindings::setpypath_from_binary ( std::string  binary_path)

set the value of sys.path before init from the supplied binary

This function will throw if bindings were not initialized in embed mode

Definition at line 90 of file start_python.cpp.

+ Here is the call graph for this function:

◆ start_ipython()

void shambindings::start_ipython ( bool  do_print,
int  argc,
char *  argv[] 
)

Start shamrock embded ipython interpreter.

This function will throw if bindings were not initialized in embed mode

Warning
This function shall not be called if more than one processes are running
Parameters
do_printprint log at python startup

Definition at line 123 of file start_python.cpp.

+ Here is the call graph for this function:

Variable Documentation

◆ check_python_is_excpeted_version

std::string check_python_is_excpeted_version
Initial value:
= R"(
import sys
cur_path = os.path.realpath(current_path)
# This is broken on MacOS and give shamrock instead i don't know why ... stupid python ...
#sysyexec = os.path.realpath(sys.executable)
# So the fix is to check that the resolved path starts with base_exec_prefix
# see https://docs.python.org/3/library/sys.html#sys.base_prefix
sysprefix = os.path.realpath(sys.base_exec_prefix)
#if cur_path != sysyexec:
if not cur_path.startswith(sysprefix):
print("Current python is not the expected version, you may be using mismatched Pythons.")
print("Current path : ",cur_path)
#print("Expected path : ",sysyexec)
print("Expected prefix : ",sysprefix)
)"

Script to check that the python distrib is the expected one.

Definition at line 66 of file start_python.cpp.

◆ runtime_set_pypath

std::optional<std::string> runtime_set_pypath = std::nullopt

value use to set the value of sys.path if set by the user at runtime

Definition at line 46 of file start_python.cpp.