[tor-commits] [stem/master] Drop use of distutils by is_available()
atagar at torproject.org
atagar at torproject.org
Sun Jul 29 21:01:27 UTC 2018
commit 9fa85ec6f751fb060f5dace804dbc3c4c407d77d
Author: Damian Johnson <atagar at torproject.org>
Date: Sun Jul 29 13:54:30 2018 -0700
Drop use of distutils by is_available()
Python3 evidently no longer bundles distutils. We only used it in our utils for
simplicity, prior to commit 943289db we manually crawled the path. Effectively
reverting commit 943289db.
https://trac.torproject.org/projects/tor/ticket/26967
---
stem/util/system.py | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/stem/util/system.py b/stem/util/system.py
index 94be6b1f..4bfde995 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -67,7 +67,6 @@ best-effort, providing **None** if the lookup fails.
import collections
import ctypes
import ctypes.util
-import distutils.spawn
import itertools
import mimetypes
import multiprocessing
@@ -383,17 +382,26 @@ def is_available(command, cached=True):
command = command.split(' ')[0]
if command in SHELL_COMMANDS:
- # we can't actually look it up, so hope the shell really provides it...
-
- return True
+ return True # we can't actually look it up, so hope the shell really provides it...
elif cached and command in CMD_AVAILABLE_CACHE:
return CMD_AVAILABLE_CACHE[command]
elif 'PATH' not in os.environ:
return False # lacking a path will cause find_executable() to internally fail
- else:
- cmd_exists = distutils.spawn.find_executable(command) is not None
- CMD_AVAILABLE_CACHE[command] = cmd_exists
- return cmd_exists
+
+ cmd_exists = False
+
+ for path in os.environ['PATH'].split(os.pathsep):
+ cmd_path = os.path.join(path, command)
+
+ if is_windows():
+ cmd_path += '.exe'
+
+ if os.path.exists(cmd_path) and os.access(cmd_path, os.X_OK):
+ cmd_exists = True
+ break
+
+ CMD_AVAILABLE_CACHE[command] = cmd_exists
+ return cmd_exists
def is_running(command):
More information about the tor-commits
mailing list