restore LD_LIBRARY_PATH for PyInstaller builds (#5421)

pull/5479/head
Mike Fährmann 6 months ago
parent 86a97d8e27
commit 9a8403917a
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

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

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

@ -171,7 +171,7 @@ class UgoiraPP(PostProcessor):
def _exec(self, args):
self.log.debug(args)
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:
print()
self.log.error("Non-zero exit status when running %s (%s)",

@ -339,7 +339,7 @@ def extract_headers(response):
@functools.lru_cache(maxsize=None)
def git_head():
try:
out, err = subprocess.Popen(
out, err = Popen(
("git", "rev-parse", "--short", "HEAD"),
stdout=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):
code_object = compile(expr, name, "eval")
return functools.partial(eval, code_object, globals or GLOBALS)

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

Loading…
Cancel
Save