diff --git a/pyinfra/connectors/local.py b/pyinfra/connectors/local.py index 03fa475d4..ab12197e1 100644 --- a/pyinfra/connectors/local.py +++ b/pyinfra/connectors/local.py @@ -1,5 +1,5 @@ import os -from distutils.spawn import find_executable +from shutil import which from tempfile import mkstemp from typing import TYPE_CHECKING, Tuple @@ -207,7 +207,7 @@ def get_file( return True def check_can_rsync(self): - if not find_executable("rsync"): + if not which("rsync"): raise NotImplementedError("The `rsync` binary is not available on this system.") def rsync( diff --git a/pyinfra/connectors/ssh.py b/pyinfra/connectors/ssh.py index 2a64ca1f9..50a3992bc 100644 --- a/pyinfra/connectors/ssh.py +++ b/pyinfra/connectors/ssh.py @@ -1,8 +1,8 @@ from __future__ import annotations import shlex -from distutils.spawn import find_executable from random import uniform +from shutil import which from socket import error as socket_error, gaierror from time import sleep from typing import TYPE_CHECKING, Any, Iterable, Optional, Tuple @@ -539,7 +539,7 @@ def check_can_rsync(self): if self.data["ssh_password"]: raise NotImplementedError("Rsync does not currently work with SSH passwords.") - if not find_executable("rsync"): + if not which("rsync"): raise NotImplementedError("The `rsync` binary is not available on this system.") def rsync( diff --git a/tests/test_api/test_api_operations.py b/tests/test_api/test_api_operations.py index e5af4fb11..f688ceb67 100644 --- a/tests/test_api/test_api_operations.py +++ b/tests/test_api/test_api_operations.py @@ -390,7 +390,7 @@ def test_rsync_op_failure(self): state = State(inventory, Config()) connect_all(state) - with patch("pyinfra.connectors.ssh.find_executable", lambda x: None): + with patch("pyinfra.connectors.ssh.which", lambda x: None): with self.assertRaises(OperationError) as context: add_op(state, files.rsync, "src", "dest")