From 9bbc66cc16a035b4f6f3efafe9b33c4182dc1fe5 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Wed, 15 Nov 2017 21:29:11 +0200 Subject: [PATCH] util: add backport for shutil.which() --- libagent/util.py | 9 +++++++-- setup.py | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libagent/util.py b/libagent/util.py index 82e60ee..15c172b 100644 --- a/libagent/util.py +++ b/libagent/util.py @@ -4,7 +4,6 @@ import contextlib import functools import io import logging -import shutil import struct log = logging.getLogger(__name__) @@ -219,7 +218,13 @@ def memoize(func): @memoize def which(cmd): """Return full path to specified command, or raise OSError if missing.""" - full_path = shutil.which(cmd) + try: + # For Python 3 + from shutil import which as _which + except ImportError: + # For Python 2 + from backports.shutil_which import which as _which # pylint: disable=relative-import + full_path = _which(cmd) if full_path is None: raise OSError('Cannot find {!r} in $PATH'.format(cmd)) log.debug('which %r => %r', cmd, full_path) diff --git a/setup.py b/setup.py index 160db4a..d051927 100755 --- a/setup.py +++ b/setup.py @@ -15,6 +15,7 @@ setup( 'libagent.ssh' ], install_requires=[ + 'backports.shutil_which>=3.5.1', 'ecdsa>=0.13', 'ed25519>=1.4', 'pymsgbox>=1.0.6',