From f5046a600ec4e03dcc30dbb079e1641503935fd6 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Sun, 9 May 2021 10:15:26 +0100 Subject: [PATCH] Tidy up --- cibuildwheel/macos.py | 2 +- cibuildwheel/typing.py | 4 +--- cibuildwheel/windows.py | 24 +++++++++++------------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index c0473964..9b4a1ec7 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -231,7 +231,7 @@ def setup_python( ) sys.exit(1) - # install pip + # ensure pip is installed call( ["python", "-m", "ensurepip", "--default-pip"], env=env, diff --git a/cibuildwheel/typing.py b/cibuildwheel/typing.py index 68b5c770..b8e91764 100644 --- a/cibuildwheel/typing.py +++ b/cibuildwheel/typing.py @@ -1,7 +1,7 @@ import os import subprocess import sys -from typing import TYPE_CHECKING, Any, NoReturn, Set, Union +from typing import TYPE_CHECKING, NoReturn, Set, Union if sys.version_info < (3, 8): from typing_extensions import Final, Literal, TypedDict @@ -26,11 +26,9 @@ __all__ = ( if TYPE_CHECKING: PopenBytes = subprocess.Popen[bytes] PathOrStr = Union[str, os.PathLike[str]] - CompletedProcess = subprocess.CompletedProcess[Any] else: PopenBytes = subprocess.Popen PathOrStr = Union[str, "os.PathLike[str]"] - CompletedProcess = subprocess.CompletedProcess PlatformName = Literal["linux", "macos", "windows"] diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index a21fa483..3dffbc75 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -10,7 +10,7 @@ from zipfile import ZipFile from .architecture import Architecture from .environment import ParsedEnvironment from .logger import log -from .typing import CompletedProcess, PathOrStr +from .typing import PathOrStr from .util import ( BuildOptions, BuildSelector, @@ -23,15 +23,12 @@ from .util import ( def call( - args: Sequence[PathOrStr], - env: Optional[Dict[str, str]] = None, - cwd: Optional[str] = None, - check: bool = True, -) -> CompletedProcess: + args: Sequence[PathOrStr], env: Optional[Dict[str, str]] = None, cwd: Optional[str] = None +) -> None: print("+ " + " ".join(str(a) for a in args)) # we use shell=True here, even though we don't need a shell due to a bug # https://bugs.python.org/issue8557 - return subprocess.run([str(a) for a in args], env=env, cwd=cwd, shell=True, check=check) + subprocess.run([str(a) for a in args], env=env, cwd=cwd, shell=True, check=True) def shell(command: str, env: Optional[Dict[str, str]] = None, cwd: Optional[str] = None) -> None: @@ -181,12 +178,13 @@ def setup_python( # make sure pip is installed and available on PATH if not (installation_path / "Scripts" / "pip.exe").exists(): # perhaps pip is installed, but not available as 'pip.exe'... - pip_is_installed = ( - call( - ["python", "-m", "pip", "--version"], env=env, cwd="C:\\cibw", check=False - ).returncode - == 0 - ) + try: + call(["python", "-m", "pip", "--version"], env=env, cwd="C:\\cibw") + except subprocess.CalledProcessError: + pip_is_installed = False + else: + pip_is_installed = True + if pip_is_installed: # if it's there, remove that version of pip. call(["python", "-m", "pip", "uninstall", "--yes", "pip"], env=env, cwd="C:\\cibw")