From 77232a07efd1eaefebb313d714d98f6487a27100 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Mon, 28 Feb 2022 20:52:21 +0100 Subject: [PATCH] replace distutils find_executable with custom version --- openpype/lib/__init__.py | 17 +++++++++-------- openpype/lib/applications.py | 8 +++++--- openpype/lib/execute.py | 4 ++-- openpype/lib/vendor_bin_utils.py | 17 +++++++++-------- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/openpype/lib/__init__.py b/openpype/lib/__init__.py index 882ff03e61..63173941c5 100644 --- a/openpype/lib/__init__.py +++ b/openpype/lib/__init__.py @@ -16,6 +16,14 @@ sys.path.insert(0, python_version_dir) site.addsitedir(python_version_dir) +from .vendor_bin_utils import ( + find_executable, + get_vendor_bin_path, + get_oiio_tools_path, + get_ffmpeg_tool_path, + ffprobe_streams, + is_oiio_supported +) from .env_tools import ( env_value_to_bool, get_paths_from_environ, @@ -48,14 +56,6 @@ from .anatomy import ( from .config import get_datetime_data -from .vendor_bin_utils import ( - get_vendor_bin_path, - get_oiio_tools_path, - get_ffmpeg_tool_path, - ffprobe_streams, - is_oiio_supported -) - from .python_module_tools import ( import_filepath, modules_from_path, @@ -184,6 +184,7 @@ from .openpype_version import ( terminal = Terminal __all__ = [ + "find_executable", "get_openpype_execute_args", "get_pype_execute_args", "get_linux_launcher_args", diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index 0b51a6629c..5613d8cccf 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -35,8 +35,10 @@ from .python_module_tools import ( modules_from_path, classes_from_module ) -from .execute import get_linux_launcher_args - +from .execute import ( + find_executable, + get_linux_launcher_args +) _logger = None @@ -646,7 +648,7 @@ class ApplicationExecutable: def _realpath(self): """Check if path is valid executable path.""" # Check for executable in PATH - result = distutils.spawn.find_executable(self.executable_path) + result = find_executable(self.executable_path) if result is not None: return result diff --git a/openpype/lib/execute.py b/openpype/lib/execute.py index f2eb97c5f5..c3e35772f3 100644 --- a/openpype/lib/execute.py +++ b/openpype/lib/execute.py @@ -4,9 +4,9 @@ import subprocess import platform import json import tempfile -import distutils.spawn from .log import PypeLogger as Logger +from .vendor_bin_utils import find_executable # MSDN process creation flag (Windows only) CREATE_NO_WINDOW = 0x08000000 @@ -341,7 +341,7 @@ def get_linux_launcher_args(*args): os.path.dirname(openpype_executable), filename ) - executable_path = distutils.spawn.find_executable(new_executable) + executable_path = find_executable(new_executable) if executable_path is None: return None launch_args = [executable_path] diff --git a/openpype/lib/vendor_bin_utils.py b/openpype/lib/vendor_bin_utils.py index bfdfd3174d..6571e2f515 100644 --- a/openpype/lib/vendor_bin_utils.py +++ b/openpype/lib/vendor_bin_utils.py @@ -3,7 +3,6 @@ import logging import json import platform import subprocess -import distutils log = logging.getLogger("Vendor utils") @@ -57,6 +56,12 @@ def find_executable(executable): return None paths = path_str.split(os.pathsep) + for path in paths: + for variant in variants: + filepath = os.path.abspath(os.path.join(path, executable)) + if os.path.isfile(filepath): + return filepath + return None def get_vendor_bin_path(bin_app): @@ -92,11 +97,7 @@ def get_oiio_tools_path(tool="oiiotool"): Default is "oiiotool". """ oiio_dir = get_vendor_bin_path("oiio") - if platform.system().lower() == "windows" and not tool.lower().endswith( - ".exe" - ): - tool = "{}.exe".format(tool) - return os.path.join(oiio_dir, tool) + return find_executable(os.path.join(oiio_dir, tool)) def get_ffmpeg_tool_path(tool="ffmpeg"): @@ -112,7 +113,7 @@ def get_ffmpeg_tool_path(tool="ffmpeg"): ffmpeg_dir = get_vendor_bin_path("ffmpeg") if platform.system().lower() == "windows": ffmpeg_dir = os.path.join(ffmpeg_dir, "bin") - return os.path.join(ffmpeg_dir, tool) + return find_executable(os.path.join(ffmpeg_dir, tool)) def ffprobe_streams(path_to_file, logger=None): @@ -173,7 +174,7 @@ def is_oiio_supported(): """ loaded_path = oiio_path = get_oiio_tools_path() if oiio_path: - oiio_path = distutils.spawn.find_executable(oiio_path) + oiio_path = find_executable(oiio_path) if not oiio_path: log.debug("OIIOTool is not configured or not present at {}".format(