From 02495230af430f562a59758f411999bfffbbdde7 Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Sun, 14 Jan 2024 09:51:05 -0500 Subject: [PATCH 1/3] staticx: Replace staticx.utils.which_exec() with shutil.which() shutil.which() was added in Python 3.3 so we no longer need our own version. --- staticx/elf.py | 5 +++-- staticx/utils.py | 8 -------- unittest/test_utils.py | 11 ----------- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/staticx/elf.py b/staticx/elf.py index 6dc383c..19ba716 100644 --- a/staticx/elf.py +++ b/staticx/elf.py @@ -5,6 +5,7 @@ import logging import errno import os +import shutil import elftools from elftools.elf.elffile import ELFFile @@ -12,7 +13,7 @@ from elftools.common.exceptions import ELFError from .errors import * -from .utils import coerce_sequence, single, which_exec +from .utils import coerce_sequence, single def verify_tools(): @@ -78,7 +79,7 @@ def get_version(self): return f"??? (exited {rc})" def which(self): - return which_exec(self.cmd) + return shutil.which(self.cmd) diff --git a/staticx/utils.py b/staticx/utils.py index 3fb0209..7a1ee4d 100644 --- a/staticx/utils.py +++ b/staticx/utils.py @@ -46,14 +46,6 @@ def copy_fileobj_to_tempfile(fsrc, **kwargs): return fdst -def which_exec(name, env=None): - for path in os.get_exec_path(env=env): - xp = os.path.join(path, name) - if os.access(xp, os.X_OK): - return xp - return None - - def is_iterable(x): """Returns true if x is iterable but not a string""" return isinstance(x, Iterable) and not isinstance(x, str) diff --git a/unittest/test_utils.py b/unittest/test_utils.py index 85e4707..8a3c8a6 100644 --- a/unittest/test_utils.py +++ b/unittest/test_utils.py @@ -64,14 +64,3 @@ def test_single_empty_default(): def test_single_key_none_default(): assert utils.single([1, 2, 3], key=lambda x: x<0, default='ok') == 'ok' - -# which_exec -def test_which_exec_common(): - def ext_which(name): - return subprocess.check_output(['which', name]).decode().strip() - - for name in ('true', 'date', 'bash', 'python3'): - assert ext_which(name) == utils.which_exec(name) - -def test_which_exec_bogus(): - assert utils.which_exec('zZzZzZzZzZzZzZz') == None From 7690cd634e6817e617fb3272cf87b6eade8550c0 Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Sun, 14 Jan 2024 01:26:17 -0500 Subject: [PATCH 2/3] staticx: Fix variable reuse of a different type in pyinstaller hook --- staticx/hooks/pyinstaller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/staticx/hooks/pyinstaller.py b/staticx/hooks/pyinstaller.py index 2aaaa19..ca0edaf 100644 --- a/staticx/hooks/pyinstaller.py +++ b/staticx/hooks/pyinstaller.py @@ -121,8 +121,8 @@ def _audit_libs(self, libs): msg = "Unsupported PyInstaller input\n\n" msg += "One or more libraries included in the PyInstaller" msg += " archive uses unsupported RPATH/RUNPATH tags:\n\n" - for e in errors: - msg += f" {e.libpath}: {e.tag}={e.value!r}\n" + for err in errors: + msg += f" {err.libpath}: {err.tag}={err.value!r}\n" msg += "\nSee https://github.com/JonathonReinhart/staticx/issues/188" raise Error(msg) From 3eea980637992a6ed0271fba75b1c14e6c0203d5 Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Sun, 14 Jan 2024 01:29:22 -0500 Subject: [PATCH 3/3] staticx: Remove redundant ArchiveError type in extract.py --- staticx/extract.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/staticx/extract.py b/staticx/extract.py index 716cd1f..77359f6 100755 --- a/staticx/extract.py +++ b/staticx/extract.py @@ -4,10 +4,9 @@ from .constants import * from .elf import * +from .errors import ArchiveError from .utils import * -class ArchiveError(Exception): - pass def open_archive(archive): f = NamedTemporaryFile(prefix='staticx-archive-', suffix='.tar')