Skip to content

Commit

Permalink
Replace calls to deprecated distutils.spawn
Browse files Browse the repository at this point in the history
This commit replaces distutils.spawn.find_executable() with
shutil.which() from the standard library. distutils is deprecated and
has been removed from Python 3.12+, causing import errors when pyinfra
is run on that version.
  • Loading branch information
diazona authored and Fizzadar committed May 13, 2024
1 parent e817e28 commit 80aca6e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pyinfra/connectors/local.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions pyinfra/connectors/ssh.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api/test_api_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 80aca6e

Please sign in to comment.