From 04bc78cc2a2902e5f4589da3724e32fbd08d3c4b Mon Sep 17 00:00:00 2001 From: Quantum Date: Wed, 22 Sep 2021 02:20:59 -0400 Subject: [PATCH] executors: use shutil.which instead of deprecated distutils See PEP 632, which suggests replacing distutils.spawn.find_executable with shutil.which. --- dmoj/executors/base_executor.py | 3 +-- dmoj/executors/shell_executor.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/dmoj/executors/base_executor.py b/dmoj/executors/base_executor.py index e9c13b907..c9549fd7f 100644 --- a/dmoj/executors/base_executor.py +++ b/dmoj/executors/base_executor.py @@ -6,7 +6,6 @@ import sys import tempfile import traceback -from distutils.spawn import find_executable from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union from dmoj.cptbox import IsolateTracer, TracedPopen, syscalls @@ -413,7 +412,7 @@ def find_command_from_list(cls, files: List[str]) -> Optional[str]: if os.path.exists(file): return file else: - path = find_executable(file) + path = shutil.which(file) if path is not None: return os.path.abspath(path) return None diff --git a/dmoj/executors/shell_executor.py b/dmoj/executors/shell_executor.py index 62344ee04..11b6f4b08 100644 --- a/dmoj/executors/shell_executor.py +++ b/dmoj/executors/shell_executor.py @@ -1,6 +1,6 @@ import os +import shutil import sys -from distutils.spawn import find_executable from dmoj.executors.script_executor import ScriptExecutor @@ -13,7 +13,7 @@ def get_shell_commands(self): return self.shell_commands def get_allowed_exec(self): - return list(map(find_executable, self.get_shell_commands())) + return list(map(shutil.which, self.get_shell_commands())) def get_fs(self): return super().get_fs() + self.get_allowed_exec()