6 #include <InterViews/session.h>
25 #if DARWIN || defined(__linux__)
26 extern const char* path_prefix_to_libnrniv();
36 #if NRNPYTHON_DYNAMICLOAD
37 int nrnpy_site_problem;
45 static int augmented = 0;
48 int err = PyRun_SimpleString(
"import sys");
50 #if defined(__linux__) || defined(DARWIN)
52 std::string lib = std::string(path_prefix_to_libnrniv());
56 if (
isDirExist(lib + std::string(
"python/neuron"))) {
57 std::string cmd = std::string(
"sys.path.append('") + lib +
"python')";
58 err = PyRun_SimpleString(cmd.c_str());
61 err = PyRun_SimpleString(
"sys.path.insert(0, '')");
72 char* cmd =
new char[strlen(
fname) + 40];
73 sprintf(cmd,
"exec(open(\"%s\").read(), globals())",
fname);
74 int err = PyRun_SimpleString(cmd);
85 int const code = PyRun_AnyFile(
fp,
fname);
89 std::cerr <<
"Could not open " <<
fname << std::endl;
103 std::string lines[3]{
104 "import code as nrnmingw_code\n",
105 "nrnmingw_interpreter = nrnmingw_code.InteractiveConsole(locals=globals())\n",
106 "nrnmingw_interpreter.interact(\"\")\n"};
107 for (
const auto&
line: lines) {
108 if (PyRun_SimpleString(
line.c_str())) {
120 for (
int i = 0;
i <
argc; ++
i) {
131 wcargv = (
wchar_t**) PyMem_Malloc(
sizeof(
wchar_t*) *
argc);
133 fprintf(stderr,
"out of memory\n");
136 for (
int i = 0;
i <
argc; ++
i) {
139 fprintf(stderr,
"out of memory\n");
146 size_t sz = mbstowcs(
NULL, s, 0);
147 wchar_t* ws =
new wchar_t[sz + 1];
148 int count = mbstowcs(ws, s, sz + 1);
173 char* _p_pyhome =
getenv(
"PYTHONHOME");
174 if (_p_pyhome ==
NULL) {
181 #if NRNPYTHON_DYNAMICLOAD
183 nrnpy_site_problem = 0;
195 PyGILState_STATE gilsav = PyGILState_Ensure();
216 bool python_error_encountered{
false};
221 python_error_encountered =
true;
224 }
else if (strlen(
arg) > 3 && strcmp(
arg + strlen(
arg) - 3,
".py") == 0) {
226 python_error_encountered =
true;
236 PyRun_InteractiveLoop(
hoc_fin,
"stdin");
241 python_error_encountered =
ret;
245 return python_error_encountered;
271 char*
p =
static_cast<char*
>(PyMem_RawMalloc(
n));
277 }
else if (r == EOF) {
278 char*
p =
static_cast<char*
>(PyMem_RawMalloc(2));
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
void hoc_retpushx(double x)
#define HocContextRestore
static char line[MAXLINE]
char * getenv(const char *s)
int const size_t const size_t n
static PyObject *(* nrnpy_reg_[])()
char * neuronhome_forward()
static wchar_t * mywstrdup(char *s)
void nrnpy_augment_path()
static void del_wcargv(int argc)
static int nrnmingw_pyrun_interactiveloop()
Like a PyRun_InteractiveLoop that does not need a FILE* Use InteractiveConsole to work around the iss...
static void copy_argv_wcargv(int argc, char **argv)
int nrnpy_pyrun(const char *)
Execute a Python script.
static char * nrnpython_getline(FILE *, FILE *, const char *)
const char * hoc_promptstr
int nrnpython_start(int)
Start the Python interpreter.
int(* p_nrnpy_pyrun)(const char *)
bool isDirExist(const std::string &path)
static const char * fname(const char *name)