From 56711529ee6202f59ef220e36974d3a2000d704b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 26 Oct 2022 05:31:22 +0200 Subject: [PATCH] Use built-in shutil.which() instead of which(1) tool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- k5test/realm.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/k5test/realm.py b/k5test/realm.py index 8b24141..2260258 100644 --- a/k5test/realm.py +++ b/k5test/realm.py @@ -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):