Skip to content

Commit

Permalink
Use built-in shutil.which() instead of which(1) tool
Browse files Browse the repository at this point in the history
Use the built-in shutil.which() function that is available since Python
3.3 instead of the external which(1) program.  The latter is not part
of POSIX and may be missing entirely (Gentoo is activately working
towards removing it)>

Signed-off-by: Michał Górny <mgorny@gentoo.org>
  • Loading branch information
mgorny authored and jborean93 committed Oct 26, 2022
1 parent f10beed commit 2dd1064
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions k5test/realm.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,13 @@ def _cfg_merge(cfg1, cfg2):


def _discover_path(name, default, paths):
stderr_out = subprocess.DEVNULL
try:
path = subprocess.check_output(["which", name], stderr=stderr_out).strip()
path = path.decode(sys.getfilesystemencoding() or sys.getdefaultencoding())
path = shutil.which(name)
if path is not None:
_LOG.debug(f"Using discovered path for {name} ({path})")
return path
except subprocess.CalledProcessError as e:
else:
path = paths.get(name, default)
_LOG.debug(f"Using default path for {name} ({path}): {e}")
return path
return path


class K5Realm(metaclass=abc.ABCMeta):
Expand Down

0 comments on commit 2dd1064

Please sign in to comment.