NEURON
nrnpython.cpp File Reference
#include "nrnpython.h"
#include "nrnpy_utils.h"
#include "oc_ansi.h"
#include <stdio.h>
#include <InterViews/resource.h>
#include <nrnoc2iv.h>
#include "hoccontext.h"
#include <ocfile.h>
#include <hocstr.h>
#include "nrnpy.h"
#include <filesystem>
#include <string>
#include <sstream>
#include <fstream>
#include <nanobind/nanobind.h>

Go to the source code of this file.

Functions

char * neuronhome_forward ()
 
static char * nrnpython_getline (FILE *, FILE *, const char *)
 
int nrnpy_pyrun (const char *fname)
 Execute a Python script. More...
 
static std::string python_sys_path_to_append ()
 
static void nrnpython_set_path (std::string_view fname)
 Reset sys.path to its value at initialisation and prepend fname. More...
 
static int nrnmingw_pyrun_interactiveloop ()
 Like a PyRun_InteractiveLoop that does not need a FILE* Use InteractiveConsole to work around the issue of mingw FILE* not being compatible with Python via the CAPI on windows11. More...
 
PyObjectnrnpy_hoc ()
 
PyObjectnrnpy_nrn ()
 
static int nrnpython_start (int b)
 Start the Python interpreter. More...
 
static void nrnpython_real ()
 Backend to nrnpython(...) in HOC/Python code. More...
 
void nrnpython_reg_real_nrnpython_cpp (neuron::python::impl_ptrs *ptrs)
 

Variables

HocStrhoc_cbufstr
 
int nrnpy_nositeflag
 
std::string nrnpy_pyexe
 
char * hoc_ctp
 
FILE * hoc_fin
 
const char * hoc_promptstr
 
int nrn_global_argc
 
char ** nrn_global_argv
 
int(* p_nrnpy_pyrun )(const char *)
 

Function Documentation

◆ neuronhome_forward()

char* neuronhome_forward ( )

Definition at line 190 of file code2.cpp.

◆ nrnmingw_pyrun_interactiveloop()

static int nrnmingw_pyrun_interactiveloop ( )
static

Like a PyRun_InteractiveLoop that does not need a FILE* Use InteractiveConsole to work around the issue of mingw FILE* not being compatible with Python via the CAPI on windows11.

Returns
0 on success, nonzero on failure.

Definition at line 166 of file nrnpython.cpp.

◆ nrnpy_hoc()

PyObject* nrnpy_hoc ( )

Definition at line 3354 of file nrnpy_hoc.cpp.

◆ nrnpy_nrn()

PyObject* nrnpy_nrn ( )

Definition at line 3005 of file nrnpy_nrn.cpp.

◆ nrnpy_pyrun()

int nrnpy_pyrun ( const char *  fname)

Execute a Python script.

Returns
0 on failure, 1 on success.

Definition at line 125 of file nrnpython.cpp.

◆ nrnpython_getline()

static char * nrnpython_getline ( FILE *  ,
FILE *  ,
const char *  prompt 
)
static

Definition at line 395 of file nrnpython.cpp.

◆ nrnpython_real()

static void nrnpython_real ( )
static

Backend to nrnpython(...) in HOC/Python code.

This can be called both with nrniv and python as the top-level executable, with different code responsible for initialising Python in the two cases. We trust that Python was initialised correctly somewhere higher up the call stack.

Definition at line 383 of file nrnpython.cpp.

◆ nrnpython_reg_real_nrnpython_cpp()

void nrnpython_reg_real_nrnpython_cpp ( neuron::python::impl_ptrs ptrs)

Definition at line 415 of file nrnpython.cpp.

◆ nrnpython_set_path()

static void nrnpython_set_path ( std::string_view  fname)
static

Reset sys.path to its value at initialisation and prepend fname.

Calling this with fname empty is appropriate ahead of executing code similar to python -c "...", if fname is non-empty then resolve symlinks in it and get the directory name – this is appropriate for python script.py compatibility.

Definition at line 108 of file nrnpython.cpp.

◆ nrnpython_start()

static int nrnpython_start ( int  b)
static

Start the Python interpreter.

  • b Mode of operation, can be 0 (finalize), 1 (initialize), or 2 (execute commands/scripts)
    Returns
    0 on success, non-zero on error
    There is an internal state variable that stores whether or not Python has been initialized. Mode 1 only has an effect if Python is not initialized, while the other modes only take effect if Python is already initialized.

Definition at line 192 of file nrnpython.cpp.

◆ python_sys_path_to_append()

static std::string python_sys_path_to_append ( )
static

Definition at line 39 of file nrnpython.cpp.

Variable Documentation

◆ hoc_cbufstr

HocStr* hoc_cbufstr
extern

Definition at line 138 of file hoc.cpp.

◆ hoc_ctp

char* hoc_ctp
extern

Definition at line 141 of file hoc.cpp.

◆ hoc_fin

FILE* hoc_fin
extern

Definition at line 152 of file hoc.cpp.

◆ hoc_promptstr

const char* hoc_promptstr
extern

Definition at line 139 of file hoc.cpp.

◆ nrn_global_argc

int nrn_global_argc
extern

Definition at line 45 of file hoc.cpp.

◆ nrn_global_argv

char** nrn_global_argv
extern

Definition at line 46 of file hoc.cpp.

◆ nrnpy_nositeflag

int nrnpy_nositeflag
extern

Definition at line 182 of file ivocmain.cpp.

◆ nrnpy_pyexe

std::string nrnpy_pyexe
extern

◆ p_nrnpy_pyrun

int(* p_nrnpy_pyrun) (const char *) ( const char *  fname)
extern

Definition at line 53 of file hoc.cpp.