From af8d24df1d0695b3fc7fb18c58bee780da12c325 Mon Sep 17 00:00:00 2001 From: Benedek Racz Date: Thu, 9 Apr 2020 10:02:04 +0200 Subject: [PATCH] Introduce WEXPECT_EXECUTABLE environment variable for pyinstaller Last versions searched wexpect executable ../wexpect/wexpect.exe in bindled mode. This was hard coded. Now the (optional) WEXPECT_EXECUTABLE environment variable can point to wexpect executable. See #12 for more details. --- wexpect/host.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/wexpect/host.py b/wexpect/host.py index b9865f3..f4654c0 100644 --- a/wexpect/host.py +++ b/wexpect/host.py @@ -342,10 +342,20 @@ class SpawnBase: raise Exception( '`sys.frozen` found, but `sys._MEIPASS` not. Only pyinstaller is supported.' ) - dirname = os.path.dirname(sys.executable) - console_executable = os.path.join(dirname, '..', 'wexpect', 'wexpect.exe') - commandLine = f'"{console_executable}" {console_args}' + # + # Find wexpect executable (aka. console reader executable). + # User can point WEXPECT_EXECUTABLE environment variable to this executable, if this + # env/var isn't specified we will find executable `../wexpect/wexpect.exe` relativly + # from the host executable. + # + try: + wexpect_executable = os.environ['WEXPECT_EXECUTABLE'] + except KeyError: + dirname = os.path.dirname(sys.executable) + wexpect_executable = os.path.join(dirname, '..', 'wexpect', 'wexpect.exe') + + commandLine = f'"{wexpect_executable}" {console_args}' else: '''Runing in a normal python process