turn on PERU_REEXEC_PYTHON by default everywhere

Fixes https://github.com/buildinspace/peru/issues/238.
This commit is contained in:
Jack O'Connor 2024-12-24 08:01:40 -08:00
parent d6cc474ba2
commit 5e11220588

View File

@ -58,24 +58,19 @@ async def plugin_get_reup_fields(plugin_context, module_type, module_fields,
return fields return fields
# Normally we prefer to execute plugins directly. This is pretty reliable on # In theory we execute plugins as opaque binaries, and the OS can run them
# Unix, where scripts can specify their interpreter with a shebang line. # however it sees fit (shebang lines on Unix, file extension associations on
# However, it's not as reliable on Windows, because the extension-interpreter # Windows). However in practice, all of our plugins are Python scripts, and
# mapping is a global config. In my experience, installing and uninstalling a # we'd rather execute them with the same interpreter that we're currently
# series of different Python interepreter versions on a Windows machine can # running. That avoids unrelaiable file association configs on Windows
# break that association, and as a result break peru, in confusing ways. (Tests # (especially when multiple versions of Python are installed), and it also
# have also been broken by default for this reason on every Windows CI provider # avoids problems on Unix where e.g. pipx installs peru in a sandbox, where
# I've ever tried.) # naively re-exec'ed scripts can't find it.
# #
# To work around this problem, we apply an extra heuristic on Windows: If a # So when a plugin executable filename ends in .py, by default we assume that
# plugin executable filename ends in .py, assume that we should re-execute the # we should re-execute the current interpreter (sys.executable) to run that
# current interpreter (sys.executable) to run that file, rather than relying on # file. For users who want to disable this heuristic, we define the
# the system shell to find the interpreter. This fixes peru on systems with # PERU_REEXEC_PYTHON env var.
# broken Python configs, and it makes no difference in the vast majority of
# other cases.
#
# For users who want to control this heuristic (either to disable it, or to
# force the same behavior on Unix), we define the PERU_REEXEC_PYTHON env var.
def _plugin_command(plugin_exe): def _plugin_command(plugin_exe):
config = os.environ.get("PERU_REEXEC_PYTHON", "default") config = os.environ.get("PERU_REEXEC_PYTHON", "default")
if config == "always": if config == "always":
@ -83,7 +78,7 @@ def _plugin_command(plugin_exe):
elif config == "never": elif config == "never":
reexec_heuristic = False reexec_heuristic = False
elif config == "default": elif config == "default":
reexec_heuristic = (os.name == 'nt') # Windows reexec_heuristic = True
else: else:
raise RuntimeError("Unrecognized value for PERU_REEXEC_PYTHON", config) raise RuntimeError("Unrecognized value for PERU_REEXEC_PYTHON", config)