Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-typing cleanups #275

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions staticx/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import logging
import errno
import os
import shutil

import elftools
from elftools.elf.elffile import ELFFile
from elftools.elf.dynamic import DynamicSegment
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():
Expand Down Expand Up @@ -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)



Expand Down
3 changes: 1 addition & 2 deletions staticx/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions staticx/hooks/pyinstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 0 additions & 8 deletions staticx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions unittest/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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