Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Py_SetProgramName to make sure sys.argv[0] is set #8631

Merged
merged 8 commits into from
Mar 22, 2021
5 changes: 5 additions & 0 deletions src/EnergyPlus/PluginManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ namespace EnergyPlus::PluginManagement {
Py_SetPath(a);
Py_SetPythonHome(a);

// must be called before Py_Initialize
// tells the interpreter the value of argv[0] to the main() function
// used by some functions to find run-time libraries relative to the interpreter executable
Py_SetProgramName((wchar_t*)programName);

// now that we have set the path, we can initialize python
// from https://docs.python.org/3/c-api/init.html
// If arg 0, it skips init registration of signal handlers, which might be useful when Python is embedded.
Expand Down
2 changes: 2 additions & 0 deletions src/EnergyPlus/PluginManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ struct EnergyPlusData;

namespace PluginManagement {

constexpr const char * programName = "python";

void registerNewCallback(EnergyPlusData &state, EMSManager::EMSCallFrom iCalledFrom, const std::function<void (void *)>& f);
void runAnyRegisteredCallbacks(EnergyPlusData &state, EMSManager::EMSCallFrom iCalledFrom, bool &anyRan);
void onBeginEnvironment(EnergyPlusData &state);
Expand Down
4 changes: 4 additions & 0 deletions src/EnergyPlus/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import sys
if not hasattr(sys, 'argv'):
sys.argv = ['']

from typing import List

from pyenergyplus.api import EnergyPlusAPI
Expand Down