From 1e4f8cb3e5d36ff34719759e187e1e2fb1099494 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 28 Dec 2023 20:09:30 +0000 Subject: [PATCH 1/2] Add frozen environment support --- src/execnet/gateway.py | 1 - src/execnet/gateway_io.py | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/execnet/gateway.py b/src/execnet/gateway.py index 6e0b8a7d..39795a01 100644 --- a/src/execnet/gateway.py +++ b/src/execnet/gateway.py @@ -194,7 +194,6 @@ def _source_of_function(function): args = sig.args if not args or args[0] != "channel": raise ValueError("expected first function argument to be `channel`") - closure = function.__closure__ codeobj = function.__code__ diff --git a/src/execnet/gateway_io.py b/src/execnet/gateway_io.py index c631f8d9..46c04050 100644 --- a/src/execnet/gateway_io.py +++ b/src/execnet/gateway_io.py @@ -18,6 +18,9 @@ class Popen2IOMaster(Popen2IO): def __init__(self, args, execmodel): PIPE = execmodel.subprocess.PIPE + if is_frozen_environment(): + args[0] = str(sys.executable) + os.environ["EXECNET_SPAWNING_SUBPROCESS"] = "1" self.popen = p = execmodel.subprocess.Popen(args, stdout=PIPE, stdin=PIPE) super().__init__(p.stdin, p.stdout, execmodel=execmodel) @@ -53,8 +56,20 @@ def shell_split_path(path): return shlex.split(path) +def is_frozen_environment(): + """Check if running in a Frozen environment.""" + return getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS') + +def get_python_executable(): + """Get the correct Python interpreter path.""" + if is_frozen_environment(): + return os.environ.get('PYTHON_EXECUTABLE', 'python') + else: + return sys.executable + def popen_args(spec): - args = shell_split_path(spec.python) if spec.python else [sys.executable] + python_executable = get_python_executable() + args = shell_split_path(spec.python) if spec.python else [python_executable] args.append("-u") if spec.dont_write_bytecode: args.append("-B") From 227da4174e349b0cc198619b5fd186c6f137df82 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:19:28 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/execnet/gateway_io.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/execnet/gateway_io.py b/src/execnet/gateway_io.py index 46c04050..6751d56b 100644 --- a/src/execnet/gateway_io.py +++ b/src/execnet/gateway_io.py @@ -58,15 +58,17 @@ def shell_split_path(path): def is_frozen_environment(): """Check if running in a Frozen environment.""" - return getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS') + return getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS") + def get_python_executable(): """Get the correct Python interpreter path.""" if is_frozen_environment(): - return os.environ.get('PYTHON_EXECUTABLE', 'python') + return os.environ.get("PYTHON_EXECUTABLE", "python") else: return sys.executable + def popen_args(spec): python_executable = get_python_executable() args = shell_split_path(spec.python) if spec.python else [python_executable]