Use the platform object itself as the interface
This commit is contained in:
+23
-11
@@ -7,7 +7,7 @@ import sys
|
||||
import tarfile
|
||||
import textwrap
|
||||
import typing
|
||||
from collections.abc import Set
|
||||
from collections.abc import Sequence, Set
|
||||
from pathlib import Path
|
||||
from tempfile import mkdtemp
|
||||
|
||||
@@ -19,9 +19,9 @@ import cibuildwheel.windows
|
||||
from cibuildwheel.architecture import Architecture, allowed_architectures_check
|
||||
from cibuildwheel.logger import log
|
||||
from cibuildwheel.options import CommandLineArguments, Options, compute_options
|
||||
from cibuildwheel.platform_interface import PlatformInterface
|
||||
from cibuildwheel.typing import (
|
||||
PLATFORMS,
|
||||
GenericPythonConfiguration,
|
||||
PlatformName,
|
||||
assert_never,
|
||||
)
|
||||
@@ -244,13 +244,25 @@ def _compute_platform(args: CommandLineArguments) -> PlatformName:
|
||||
return _compute_platform_ci()
|
||||
|
||||
|
||||
def get_platform_interface(platform: PlatformName) -> PlatformInterface:
|
||||
class PlatformModule(typing.Protocol):
|
||||
# note that as per PEP544, the self argument is ignored when the protocol
|
||||
# is applied to a module
|
||||
def get_python_configurations(
|
||||
self, build_selector: BuildSelector, architectures: Set[Architecture]
|
||||
) -> Sequence[GenericPythonConfiguration]:
|
||||
...
|
||||
|
||||
def build(self, options: Options, tmp_path: Path) -> None:
|
||||
...
|
||||
|
||||
|
||||
def get_platform_module(platform: PlatformName) -> PlatformModule:
|
||||
if platform == "linux": # noqa: SIM116
|
||||
return cibuildwheel.linux.interface
|
||||
return cibuildwheel.linux
|
||||
elif platform == "windows":
|
||||
return cibuildwheel.windows.interface
|
||||
return cibuildwheel.windows
|
||||
elif platform == "macos":
|
||||
return cibuildwheel.macos.interface
|
||||
return cibuildwheel.macos
|
||||
assert_never(platform)
|
||||
|
||||
|
||||
@@ -267,9 +279,9 @@ def build_in_directory(args: CommandLineArguments) -> None:
|
||||
print(msg, file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
interface = get_platform_interface(platform)
|
||||
platform_module = get_platform_module(platform)
|
||||
identifiers = get_build_identifiers(
|
||||
interface=interface,
|
||||
platform_module=platform_module,
|
||||
build_selector=options.globals.build_selector,
|
||||
architectures=options.globals.architectures,
|
||||
)
|
||||
@@ -315,7 +327,7 @@ def build_in_directory(args: CommandLineArguments) -> None:
|
||||
with cibuildwheel.util.print_new_wheels(
|
||||
"\n{n} wheels produced in {m:.0f} minutes:", output_dir
|
||||
):
|
||||
interface.build(options, tmp_path)
|
||||
platform_module.build(options, tmp_path)
|
||||
finally:
|
||||
# avoid https://github.com/python/cpython/issues/86962 by performing
|
||||
# cleanup manually
|
||||
@@ -358,9 +370,9 @@ def print_preamble(platform: str, options: Options, identifiers: list[str]) -> N
|
||||
|
||||
|
||||
def get_build_identifiers(
|
||||
interface: PlatformInterface, build_selector: BuildSelector, architectures: Set[Architecture]
|
||||
platform_module: PlatformModule, build_selector: BuildSelector, architectures: Set[Architecture]
|
||||
) -> list[str]:
|
||||
python_configurations = interface.get_python_configurations(build_selector, architectures)
|
||||
python_configurations = platform_module.get_python_configurations(build_selector, architectures)
|
||||
return [config.identifier for config in python_configurations]
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ from .architecture import Architecture
|
||||
from .logger import log
|
||||
from .oci_container import OCIContainer
|
||||
from .options import Options
|
||||
from .platform_interface import PlatformInterface
|
||||
from .typing import OrderedDict, PathOrStr, assert_never
|
||||
from .util import (
|
||||
AlreadyBuiltWheelError,
|
||||
@@ -484,6 +483,3 @@ def troubleshoot(options: Options, error: Exception) -> None:
|
||||
print(" Files detected:")
|
||||
print("\n".join(f" {f}" for f in so_files))
|
||||
print()
|
||||
|
||||
|
||||
interface = PlatformInterface(get_python_configurations=get_python_configurations, build=build)
|
||||
|
||||
@@ -19,7 +19,6 @@ from .architecture import Architecture
|
||||
from .environment import ParsedEnvironment
|
||||
from .logger import log
|
||||
from .options import Options
|
||||
from .platform_interface import PlatformInterface
|
||||
from .typing import Literal, PathOrStr, assert_never
|
||||
from .util import (
|
||||
CIBW_CACHE_PATH,
|
||||
@@ -623,6 +622,3 @@ def build(options: Options, tmp_path: Path) -> None:
|
||||
f"Command {error.cmd} failed with code {error.returncode}. {error.stdout}"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
interface = PlatformInterface(get_python_configurations=get_python_configurations, build=build)
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
from collections.abc import Callable, Sequence, Set
|
||||
from pathlib import Path
|
||||
|
||||
from .architecture import Architecture
|
||||
from .options import Options
|
||||
from .typing import GenericPythonConfiguration
|
||||
from .util import BuildSelector
|
||||
|
||||
|
||||
# Can't make it frozen because we monkeypatch "build" in unit tests
|
||||
@dataclasses.dataclass()
|
||||
class PlatformInterface:
|
||||
get_python_configurations: Callable[
|
||||
[BuildSelector, Set[Architecture]], Sequence[GenericPythonConfiguration]
|
||||
]
|
||||
build: Callable[[Options, Path], None]
|
||||
@@ -20,7 +20,6 @@ from .architecture import Architecture
|
||||
from .environment import ParsedEnvironment
|
||||
from .logger import log
|
||||
from .options import Options
|
||||
from .platform_interface import PlatformInterface
|
||||
from .typing import PathOrStr, assert_never
|
||||
from .util import (
|
||||
CIBW_CACHE_PATH,
|
||||
@@ -575,6 +574,3 @@ def build(options: Options, tmp_path: Path) -> None:
|
||||
f"Command {error.cmd} failed with code {error.returncode}. {error.stdout}"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
interface = PlatformInterface(get_python_configurations=get_python_configurations, build=build)
|
||||
|
||||
@@ -85,9 +85,9 @@ def platform(request, monkeypatch):
|
||||
def intercepted_build_args(monkeypatch):
|
||||
intercepted = ArgsInterceptor()
|
||||
|
||||
monkeypatch.setattr(linux.interface, "build", intercepted)
|
||||
monkeypatch.setattr(macos.interface, "build", intercepted)
|
||||
monkeypatch.setattr(windows.interface, "build", intercepted)
|
||||
monkeypatch.setattr(linux, "build", intercepted)
|
||||
monkeypatch.setattr(macos, "build", intercepted)
|
||||
monkeypatch.setattr(windows, "build", intercepted)
|
||||
|
||||
yield intercepted
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from cibuildwheel.__main__ import get_build_identifiers, get_platform_interface
|
||||
from cibuildwheel.__main__ import get_build_identifiers, get_platform_module
|
||||
from cibuildwheel.bashlex_eval import local_environment_executor
|
||||
from cibuildwheel.environment import parse_environment
|
||||
from cibuildwheel.options import (
|
||||
@@ -49,9 +49,9 @@ def test_options_1(tmp_path, monkeypatch):
|
||||
|
||||
options = Options(platform="linux", command_line_arguments=args, env={})
|
||||
|
||||
interface = get_platform_interface("linux")
|
||||
module = get_platform_module("linux")
|
||||
identifiers = get_build_identifiers(
|
||||
interface=interface,
|
||||
platform_module=module,
|
||||
build_selector=options.globals.build_selector,
|
||||
architectures=options.globals.architectures,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user