Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions distutils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
import re
import sys
from abc import abstractmethod
from collections.abc import Callable, MutableSequence
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, cast, overload
from collections.abc import Callable, Sequence
from typing import (
TYPE_CHECKING,
Any,
ClassVar,
TypeVar,
cast,
overload,
)

from . import _modified, archive_util, dir_util, file_util, util
from ._log import log
Expand Down Expand Up @@ -451,7 +458,7 @@ def move_file(
return file_util.move_file(src, dst)

def spawn(
self, cmd: MutableSequence[str], search_path: bool = True, level: int = 1
self, cmd: Sequence[bytes | os.PathLike[bytes] | str | os.PathLike[str]]
) -> None:
"""Spawn an external command respecting dry-run flag."""
from distutils.spawn import spawn
Expand Down
14 changes: 4 additions & 10 deletions distutils/compilers/C/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@
import subprocess
import sys
import warnings
from collections.abc import Callable, Iterable, MutableSequence, Sequence
from typing import (
TYPE_CHECKING,
ClassVar,
Literal,
TypeVar,
overload,
)
from collections.abc import Callable, Iterable, Sequence
from typing import TYPE_CHECKING, ClassVar, Literal, TypeVar, overload

from more_itertools import always_iterable

Expand Down Expand Up @@ -1167,7 +1161,7 @@ def execute(

def call(
self,
cmd: MutableSequence[bytes | str | os.PathLike[str]],
cmd: Sequence[bytes | os.PathLike[bytes] | str | os.PathLike[str]],
*,
env: _ENV | None = None,
**kwargs,
Expand All @@ -1178,7 +1172,7 @@ def call(

def spawn(
self,
cmd: MutableSequence[bytes | str | os.PathLike[str]],
cmd: Sequence[bytes | os.PathLike[bytes] | str | os.PathLike[str]],
*,
env: _ENV | None = None,
**kwargs,
Expand Down
19 changes: 12 additions & 7 deletions distutils/compilers/C/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@
import os
import subprocess
import tempfile
from collections.abc import Iterable, Iterator
from collections.abc import Iterable, Iterator, Sequence
from itertools import count
from pathlib import Path
from typing import ClassVar

with contextlib.suppress(ImportError):
import winreg

from itertools import count

from ..errors import PlatformError
from ..logging import get_logger
from ..platform.detect import get_host_platform, get_platform
from . import base
from .base import gen_lib_options
from .errors import CompileError, LibError, LinkError

with contextlib.suppress(ImportError):
import winreg

log = get_logger(__name__)


Expand Down Expand Up @@ -618,7 +617,13 @@ def link(
else:
log.debug("skipping %s (up-to-date)", output_filename)

def call(self, cmd, *, env=None, **kwargs):
def call(
self,
cmd: Sequence[bytes | os.PathLike[bytes] | str | os.PathLike[str]],
*,
env=None,
**kwargs,
) -> None:
env = dict(os.environ, PATH=self._paths)
return super().call(cmd, env=env, **kwargs)

Expand Down
15 changes: 12 additions & 3 deletions distutils/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
import subprocess
import sys
import warnings
from collections.abc import MutableSequence
from collections.abc import Sequence
from typing import TYPE_CHECKING

from ._log import log
from .errors import DistutilsExecError

if TYPE_CHECKING:
from subprocess import _ENV


@contextlib.contextmanager
def _translate_errors(cmd):
Expand All @@ -30,7 +34,12 @@ def _translate_errors(cmd):
) from err


def spawn(cmd: MutableSequence[bytes | str | os.PathLike[str]], **kwargs) -> None:
def spawn(
cmd: Sequence[bytes | os.PathLike[bytes] | str | os.PathLike[str]],
*,
env: _ENV | None = None,
**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.
Expand All @@ -42,7 +51,7 @@ def spawn(cmd: MutableSequence[bytes | str | os.PathLike[str]], **kwargs) -> Non
"""
log.info(subprocess.list2cmdline(cmd))
with _translate_errors(cmd):
subprocess.check_call(cmd, **kwargs)
subprocess.check_call(cmd, env=env, **kwargs)


def find_executable(executable: str, path: str | None = None) -> str | None:
Expand Down
Loading