diff --git a/dvc/dagascii.py b/dvc/dagascii.py index e7058c3fd5..68459120c4 100644 --- a/dvc/dagascii.py +++ b/dvc/dagascii.py @@ -7,7 +7,6 @@ import os import pydoc import sys -from distutils.spawn import find_executable from grandalf.graphs import Edge from grandalf.graphs import Graph @@ -16,7 +15,7 @@ from grandalf.routing import EdgeViewer from grandalf.routing import route_with_lines -from dvc.utils import boxify +from dvc.utils import boxify, is_exec_found logger = logging.getLogger(__name__) @@ -39,8 +38,7 @@ def find_pager(pager_cmd, pager_cmd_with_format, pager_env_name): if sys.stdout.isatty(): - less_found = find_executable(pager_cmd) is not None - if less_found: + if is_exec_found(pager_cmd): pager_cmd = os.getenv(pager_env_name, pager_cmd_with_format) def less_pager(text): diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index 68ba418778..f1053eb9c7 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -420,3 +420,8 @@ def resolve_output(inp, out): if os.path.isdir(out): return os.path.join(out, name) return out + + +def is_exec_found(exec_name): + cmd = '({}) 2>/dev/null'.format(exec_name) + return hasattr(os, 'system') and os.system(cmd) == 0 diff --git a/tests/func/test_utils.py b/tests/func/test_utils.py index 594fdc332d..40c575e4f4 100644 --- a/tests/func/test_utils.py +++ b/tests/func/test_utils.py @@ -88,3 +88,13 @@ def test_makedirs_permissions(tmpdir): assert stat.S_IMODE(os.stat(test_dir).st_mode) == dir_mode assert stat.S_IMODE(os.stat(intermediate_dir).st_mode) == dir_mode + + +def test_is_exec_found_returns_true_when_program_exists(): + result = utils.is_exec_found("python") + assert result == True + + +def test_is_exec_found_returns_false_when_program_is_missing(): + result = utils.is_exec_found("some-missing-program") + assert result == False