restore LD_LIBRARY_PATH for PyInstaller builds (#5421)

This commit is contained in:
Mike Fährmann
2024-04-06 03:24:51 +02:00
parent 86a97d8e27
commit 9a8403917a
5 changed files with 36 additions and 10 deletions

View File

@@ -857,7 +857,7 @@ class DatabaseConnection():
def Popen_communicate(*args): def Popen_communicate(*args):
proc = subprocess.Popen( proc = util.Popen(
args, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) args, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
try: try:
stdout, stderr = proc.communicate() stdout, stderr = proc.communicate()

View File

@@ -10,7 +10,6 @@
from .common import PostProcessor from .common import PostProcessor
from .. import util, formatter from .. import util, formatter
import subprocess
import os import os
import re import re
@@ -80,14 +79,14 @@ class ExecPP(PostProcessor):
def _exec(self, args, shell): def _exec(self, args, shell):
self.log.debug("Running '%s'", args) self.log.debug("Running '%s'", args)
retcode = subprocess.Popen(args, shell=shell).wait() retcode = util.Popen(args, shell=shell).wait()
if retcode: if retcode:
self.log.warning("'%s' returned with non-zero exit status (%d)", self.log.warning("'%s' returned with non-zero exit status (%d)",
args, retcode) args, retcode)
def _exec_async(self, args, shell): def _exec_async(self, args, shell):
self.log.debug("Running '%s'", args) self.log.debug("Running '%s'", args)
subprocess.Popen(args, shell=shell) util.Popen(args, shell=shell)
def _replace(self, match): def _replace(self, match):
name = match.group(1) name = match.group(1)

View File

@@ -171,7 +171,7 @@ class UgoiraPP(PostProcessor):
def _exec(self, args): def _exec(self, args):
self.log.debug(args) self.log.debug(args)
out = None if self.output else subprocess.DEVNULL out = None if self.output else subprocess.DEVNULL
retcode = subprocess.Popen(args, stdout=out, stderr=out).wait() retcode = util.Popen(args, stdout=out, stderr=out).wait()
if retcode: if retcode:
print() print()
self.log.error("Non-zero exit status when running %s (%s)", self.log.error("Non-zero exit status when running %s (%s)",

View File

@@ -339,7 +339,7 @@ def extract_headers(response):
@functools.lru_cache(maxsize=None) @functools.lru_cache(maxsize=None)
def git_head(): def git_head():
try: try:
out, err = subprocess.Popen( out, err = Popen(
("git", "rev-parse", "--short", "HEAD"), ("git", "rev-parse", "--short", "HEAD"),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
@@ -579,6 +579,33 @@ GLOBALS = {
} }
if EXECUTABLE and hasattr(sys, "_MEIPASS"):
# https://github.com/pyinstaller/pyinstaller/blob/develop/doc
# /runtime-information.rst#ld_library_path--libpath-considerations
_popen_env = os.environ.copy()
orig = _popen_env.get("LD_LIBRARY_PATH_ORIG")
if orig is None:
_popen_env.pop("LD_LIBRARY_PATH", None)
else:
_popen_env["LD_LIBRARY_PATH"] = orig
orig = _popen_env.get("DYLD_LIBRARY_PATH_ORIG")
if orig is None:
_popen_env.pop("DYLD_LIBRARY_PATH", None)
else:
_popen_env["DYLD_LIBRARY_PATH"] = orig
del orig
class Popen(subprocess.Popen):
def __init__(self, args, **kwargs):
kwargs["env"] = _popen_env
subprocess.Popen.__init__(self, args, **kwargs)
else:
Popen = subprocess.Popen
def compile_expression(expr, name="<expr>", globals=None): def compile_expression(expr, name="<expr>", globals=None):
code_object = compile(expr, name, "eval") code_object = compile(expr, name, "eval")
return functools.partial(eval, code_object, globals or GLOBALS) return functools.partial(eval, code_object, globals or GLOBALS)

View File

@@ -172,7 +172,7 @@ class ExecTest(BasePostprocessorTest):
"command": "echo {} {_path} {_directory} {_filename} && rm {};", "command": "echo {} {_path} {_directory} {_filename} && rm {};",
}) })
with patch("subprocess.Popen") as p: with patch("gallery_dl.util.Popen") as p:
i = Mock() i = Mock()
i.wait.return_value = 0 i.wait.return_value = 0
p.return_value = i p.return_value = i
@@ -192,7 +192,7 @@ class ExecTest(BasePostprocessorTest):
"\fE _directory.upper()"], "\fE _directory.upper()"],
}) })
with patch("subprocess.Popen") as p: with patch("gallery_dl.util.Popen") as p:
i = Mock() i = Mock()
i.wait.return_value = 0 i.wait.return_value = 0
p.return_value = i p.return_value = i
@@ -212,7 +212,7 @@ class ExecTest(BasePostprocessorTest):
"command": "echo {}", "command": "echo {}",
}) })
with patch("subprocess.Popen") as p: with patch("gallery_dl.util.Popen") as p:
i = Mock() i = Mock()
i.wait.return_value = 123 i.wait.return_value = 123
p.return_value = i p.return_value = i
@@ -230,7 +230,7 @@ class ExecTest(BasePostprocessorTest):
"command": "echo {}", "command": "echo {}",
}) })
with patch("subprocess.Popen") as p: with patch("gallery_dl.util.Popen") as p:
i = Mock() i = Mock()
p.return_value = i p.return_value = i
self._trigger(("after",)) self._trigger(("after",))