Skip to content

Commit

Permalink
staticx: Replace staticx.utils.which_exec() with shutil.which()
Browse files Browse the repository at this point in the history
shutil.which() was added in Python 3.3 so we no longer need our own
version.
  • Loading branch information
JonathonReinhart committed Jan 14, 2024
1 parent 2a8214e commit 0249523
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
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
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

0 comments on commit 0249523

Please sign in to comment.