Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate find_executable. #250

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions distutils/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

Provides the 'spawn()' function, a front-end to various platform-
specific functions for launching another program in a sub-process.
Also provides the 'find_executable()' to search the path for a given
executable name.
"""

from __future__ import annotations

import os
import platform
import shutil
import subprocess
import sys
import warnings

from typing import Mapping

Expand Down Expand Up @@ -63,7 +63,7 @@ def spawn(cmd, search_path=True, verbose=False, dry_run=False, env=None):
return

if search_path:
executable = find_executable(cmd[0])
executable = shutil.which(cmd[0])
if executable is not None:
cmd[0] = executable

Expand All @@ -85,6 +85,9 @@ def find_executable(executable, path=None):
A string listing directories separated by 'os.pathsep'; defaults to
os.environ['PATH']. Returns the complete filename or None if not found.
"""
warnings.warn(
'Use shutil.which instead of find_executable', DeprecationWarning, stacklevel=2
)
_, ext = os.path.splitext(executable)
if (sys.platform == 'win32') and (ext != '.exe'):
executable = executable + '.exe'
Expand Down
5 changes: 3 additions & 2 deletions distutils/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
by import rather than matching pre-defined names.
"""

import shutil
from typing import Sequence


Expand All @@ -19,7 +20,7 @@ def missing_compiler_executable(cmd_names: Sequence[str] = []): # pragma: no co
missing.

"""
from distutils import ccompiler, errors, spawn, sysconfig
from distutils import ccompiler, errors, sysconfig

compiler = ccompiler.new_compiler()
sysconfig.customize_compiler(compiler)
Expand All @@ -37,5 +38,5 @@ def missing_compiler_executable(cmd_names: Sequence[str] = []): # pragma: no co
assert cmd is not None, "the '%s' executable is not configured" % name
elif not cmd:
continue
if spawn.find_executable(cmd[0]) is None:
if shutil.which(cmd[0]) is None:
return cmd[0]
4 changes: 2 additions & 2 deletions distutils/tests/test_archive_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _create_files(self):
return tmpdir

@pytest.mark.usefixtures('needs_zlib')
@pytest.mark.skipif("not (find_executable('tar') and find_executable('gzip'))")
@pytest.mark.skipif("not (shutil.which('tar') and shutil.which('gzip'))")
def test_tarfile_vs_tar(self):
tmpdir = self._create_files()
tmpdir2 = self.mkdtemp()
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_tarfile_vs_tar(self):
tarball = base_name + '.tar'
assert os.path.exists(tarball)

@pytest.mark.skipif("not find_executable('compress')")
@pytest.mark.skipif("not shutil.which('compress')")
def test_compress_deprecated(self):
tmpdir = self._create_files()
base_name = os.path.join(self.mkdtemp(), 'archive')
Expand Down
10 changes: 5 additions & 5 deletions distutils/tests/test_bdist_rpm.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Tests for distutils.command.bdist_rpm."""

import os
import shutil # noqa: F401
import sys
from distutils.command.bdist_rpm import bdist_rpm
from distutils.core import Distribution
from distutils.spawn import find_executable # noqa: F401
from distutils.tests import support

import pytest
Expand Down Expand Up @@ -43,8 +43,8 @@ class TestBuildRpm(
):
@mac_woes
@requires_zlib()
@pytest.mark.skipif("not find_executable('rpm')")
@pytest.mark.skipif("not find_executable('rpmbuild')")
@pytest.mark.skipif("not shutil.which('rpm')")
@pytest.mark.skipif("not shutil.which('rpmbuild')")
def test_quiet(self):
# let's create a package
tmp_dir = self.mkdtemp()
Expand Down Expand Up @@ -86,8 +86,8 @@ def test_quiet(self):
@mac_woes
@requires_zlib()
# https://bugs.python.org/issue1533164
@pytest.mark.skipif("not find_executable('rpm')")
@pytest.mark.skipif("not find_executable('rpmbuild')")
@pytest.mark.skipif("not shutil.which('rpm')")
@pytest.mark.skipif("not shutil.which('rpmbuild')")
def test_no_optimize_flag(self):
# let's create a package that breaks bdist_rpm
tmp_dir = self.mkdtemp()
Expand Down
10 changes: 5 additions & 5 deletions distutils/tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import pathlib
import shutil # noqa: F401
import tarfile
import warnings
import zipfile
Expand All @@ -10,7 +11,6 @@
from distutils.core import Distribution
from distutils.errors import DistutilsOptionError
from distutils.filelist import FileList
from distutils.spawn import find_executable # noqa: F401
from distutils.tests.test_config import BasePyPIRCCommandTestCase
from os.path import join
from textwrap import dedent
Expand Down Expand Up @@ -137,8 +137,8 @@ def test_prune_file_list(self):
assert sorted(content) == ['fake-1.0/' + x for x in expected]

@pytest.mark.usefixtures('needs_zlib')
@pytest.mark.skipif("not find_executable('tar')")
@pytest.mark.skipif("not find_executable('gzip')")
@pytest.mark.skipif("not shutil.which('tar')")
@pytest.mark.skipif("not shutil.which('gzip')")
def test_make_distribution(self):
# now building a sdist
dist, cmd = self.get_cmd()
Expand Down Expand Up @@ -434,8 +434,8 @@ def test_manual_manifest(self):
@pytest.mark.usefixtures('needs_zlib')
@require_unix_id
@require_uid_0
@pytest.mark.skipif("not find_executable('tar')")
@pytest.mark.skipif("not find_executable('gzip')")
@pytest.mark.skipif("not shutil.which('tar')")
@pytest.mark.skipif("not shutil.which('gzip')")
def test_make_distribution_owner_group(self):
# now building a sdist
dist, cmd = self.get_cmd()
Expand Down
5 changes: 4 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ filterwarnings=
# suppress warnings in deprecated compilers
ignore:(bcpp|msvc9?)compiler is deprecated

# suppress well know deprecation warning
# suppress well known deprecation warning
ignore:distutils.log.Log is deprecated

# suppress known deprecation
ignore:Use shutil.which instead of find_executable:DeprecationWarning