| 317 | } |
| 318 | |
| 319 | PythonEngine::PythonEngine(EnergyPlusData &state) : eplusRunningViaPythonAPI(state.dataPluginManager->eplusRunningViaPythonAPI) |
| 320 | { |
| 321 | // we'll need the program directory for a few things so get it once here at the top and sanitize it |
| 322 | fs::path programDir; |
| 323 | if (state.dataGlobal->installRootOverride) { |
| 324 | programDir = state.dataStrGlobals->exeDirectoryPath; |
| 325 | } else { |
| 326 | programDir = FileSystem::getParentDirectoryPath(FileSystem::getAbsolutePath(FileSystem::getProgramPath())); |
| 327 | } |
| 328 | fs::path const pathToPythonPackages = programDir / "python_lib"; |
| 329 | |
| 330 | initPython(state, pathToPythonPackages); |
| 331 | |
| 332 | // we also need to set an extra import path to find some dynamic library loading stuff, again make it relative to the binary |
| 333 | addToPythonPath(state, programDir / "python_lib/lib-dynload", false); |
| 334 | |
| 335 | // now for additional paths: |
| 336 | // we'll always want to add the program executable directory to PATH so that Python can find the installed pyenergyplus package |
| 337 | // we will then optionally add the current working directory to allow Python to find scripts in the current directory |
| 338 | // we will then optionally add the directory of the running IDF to allow Python to find scripts kept next to the IDF |
| 339 | // we will then optionally add any additional paths the user specifies on the search paths object |
| 340 | |
| 341 | // so add the executable directory here |
| 342 | addToPythonPath(state, programDir, false); |
| 343 | |
| 344 | PyObject *m = PyImport_AddModule("__main__"); |
| 345 | if (m == nullptr) { |
| 346 | throw std::runtime_error("Unable to add module __main__ for python script execution"); |
| 347 | } |
| 348 | m_globalDict = PyModule_GetDict(m); |
| 349 | } |
| 350 | |
| 351 | void PythonEngine::exec(std::string_view sv) |
| 352 | { |
nothing calls this directly
no test coverage detected