| Server IP : 129.212.197.240 / Your IP : 216.73.216.19 Web Server : Apache/2.4.29 (Ubuntu) System : Linux snapshots-s-1vcpu-1gb-nyc1-261112-2000 4.15.0-197-generic #208-Ubuntu SMP Tue Nov 1 17:23:37 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 7.2.24-0ubuntu0.18.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /snap/certbot/current/lib/python3.12/site-packages/setuptools/_distutils/ |
Upload File : |
"""distutils.spawn
Provides the 'spawn()' function, a front-end to various platform-
specific functions for launching another program in a sub-process.
"""
from __future__ import annotations
import contextlib
import os
import subprocess
import sys
import warnings
from collections.abc import MutableSequence
from ._log import log
from .errors import DistutilsExecError
@contextlib.contextmanager
def _translate_errors(cmd):
"""Reraise a subprocess failure running 'cmd' as a DistutilsExecError."""
try:
yield
except OSError as exc:
raise DistutilsExecError(f"command {cmd[0]!r} failed: {exc.args[-1]}") from exc
except subprocess.CalledProcessError as err:
raise DistutilsExecError(
f"command {cmd[0]!r} failed with exit code {err.returncode}"
) from err
def spawn(cmd: MutableSequence[bytes | str | os.PathLike[str]], **kwargs) -> None:
"""Run another program, specified as a command list 'cmd', in a new process.
'cmd' is just the argument list for the new process, ie.
cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
Any keyword arguments are passed through to ``subprocess.check_call``.
Raise DistutilsExecError if running the program fails in any way; just
return on success.
"""
log.info(subprocess.list2cmdline(cmd))
with _translate_errors(cmd):
subprocess.check_call(cmd, **kwargs)
def find_executable(executable: str, path: str | None = None) -> str | None:
"""Tries to find 'executable' in the directories listed in 'path'.
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'
if os.path.isfile(executable):
return executable
if path is None:
path = os.environ.get('PATH', None)
# bpo-35755: Don't fall through if PATH is the empty string
if path is None:
try:
path = os.confstr("CS_PATH")
except (AttributeError, ValueError):
# os.confstr() or CS_PATH is not available
path = os.defpath
# PATH='' doesn't match, whereas PATH=':' looks in the current directory
if not path:
return None
paths = path.split(os.pathsep)
for p in paths:
f = os.path.join(p, executable)
if os.path.isfile(f):
# the file exists, we have a shot at spawn working
return f
return None