Skip to content

Commit 686712f

Browse files
mndevecihawflau
andauthored
fix: remove ld_library_path when running from native executable (#602)
* fix: remove ld_library_path when running from native executable * reformat with black --------- Co-authored-by: Wing Fung Lau <[email protected]>
1 parent ed01833 commit 686712f

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

aws_lambda_builders/workflows/python_pip/packager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,14 @@ def _execute(self, command, args, env_vars=None, shim=None):
772772
main_args = [command] + args
773773
LOG.debug("calling pip %s", " ".join(main_args))
774774
rc, out, err = self._wrapped_pip.main(main_args, env_vars=env_vars, shim=shim)
775+
LOG.debug("pip stdout: %s", out)
776+
LOG.debug("pip stderr: %s", err)
775777
return rc, out, err
776778

777779
def build_wheel(self, wheel, directory, compile_c=True):
778780
"""Build an sdist into a wheel file."""
779781
arguments = ["--no-deps", "--wheel-dir", directory, wheel]
780-
env_vars = self._osutils.environ()
782+
env_vars = self._osutils.original_environ()
781783
shim = ""
782784
if not compile_c:
783785
env_vars.update(pip_no_compile_c_env_vars)

aws_lambda_builders/workflows/python_pip/utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717

1818
class OSUtils(object):
19-
def environ(self):
20-
return os.environ
21-
2219
def original_environ(self):
2320
# https://pyinstaller.readthedocs.io/en/stable/runtime-information.html#ld-library-path-libpath-considerations
2421
env = dict(os.environ)

tests/functional/workflows/python_pip/test_packager.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import tarfile
55
import io
66
from collections import defaultdict, namedtuple
7-
from unittest import mock
7+
from unittest import TestCase, mock
88

99
import pytest
1010

@@ -182,7 +182,7 @@ def osutils():
182182
@pytest.fixture
183183
def empty_env_osutils():
184184
class EmptyEnv(object):
185-
def environ(self):
185+
def original_environ(self):
186186
return {}
187187

188188
return EmptyEnv()
@@ -830,6 +830,16 @@ def test_build_into_existing_dir_with_preinstalled_packages(self, tmpdir, osutil
830830
assert installed_packages == ["bar"]
831831

832832

833+
class TestPipRunner(TestCase):
834+
def test_build_wheel_calls_pip_without_ld_library_path(self):
835+
pip_mock = mock.Mock()
836+
pip_mock.main.return_value = (0, "out", "err")
837+
os_utils_mock = mock.Mock()
838+
pip_runner = PipRunner(mock.Mock(), pip_mock, os_utils_mock)
839+
pip_runner.build_wheel("wheel", "dir")
840+
os_utils_mock.original_environ.assert_called_once()
841+
842+
833843
class TestSubprocessPip(object):
834844
def test_can_invoke_pip(self):
835845
pip = SubprocessPip(python_exe=sys.executable)

tests/unit/workflows/python_pip/test_packager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class CustomEnv(OSUtils):
6161
def __init__(self, env):
6262
self._env = env
6363

64-
def environ(self):
64+
def original_environ(self):
6565
return self._env
6666

6767

0 commit comments

Comments
 (0)