Merge pull request #1461 from hoodmane/platform-interface
chore: Add a PlatformModule type
This commit is contained in:
+27
-27
@@ -244,6 +244,28 @@ def _compute_platform(args: CommandLineArguments) -> PlatformName:
|
|||||||
return _compute_platform_ci()
|
return _compute_platform_ci()
|
||||||
|
|
||||||
|
|
||||||
|
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":
|
||||||
|
return cibuildwheel.linux
|
||||||
|
if platform == "windows":
|
||||||
|
return cibuildwheel.windows
|
||||||
|
if platform == "macos":
|
||||||
|
return cibuildwheel.macos
|
||||||
|
assert_never(platform) # noqa: RET503
|
||||||
|
|
||||||
|
|
||||||
def build_in_directory(args: CommandLineArguments) -> None:
|
def build_in_directory(args: CommandLineArguments) -> None:
|
||||||
platform: PlatformName = _compute_platform(args)
|
platform: PlatformName = _compute_platform(args)
|
||||||
options = compute_options(platform=platform, command_line_arguments=args, env=os.environ)
|
options = compute_options(platform=platform, command_line_arguments=args, env=os.environ)
|
||||||
@@ -257,8 +279,9 @@ def build_in_directory(args: CommandLineArguments) -> None:
|
|||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
platform_module = get_platform_module(platform)
|
||||||
identifiers = get_build_identifiers(
|
identifiers = get_build_identifiers(
|
||||||
platform=platform,
|
platform_module=platform_module,
|
||||||
build_selector=options.globals.build_selector,
|
build_selector=options.globals.build_selector,
|
||||||
architectures=options.globals.architectures,
|
architectures=options.globals.architectures,
|
||||||
)
|
)
|
||||||
@@ -304,14 +327,7 @@ def build_in_directory(args: CommandLineArguments) -> None:
|
|||||||
with cibuildwheel.util.print_new_wheels(
|
with cibuildwheel.util.print_new_wheels(
|
||||||
"\n{n} wheels produced in {m:.0f} minutes:", output_dir
|
"\n{n} wheels produced in {m:.0f} minutes:", output_dir
|
||||||
):
|
):
|
||||||
if platform == "linux":
|
platform_module.build(options, tmp_path)
|
||||||
cibuildwheel.linux.build(options, tmp_path)
|
|
||||||
elif platform == "windows":
|
|
||||||
cibuildwheel.windows.build(options, tmp_path)
|
|
||||||
elif platform == "macos":
|
|
||||||
cibuildwheel.macos.build(options, tmp_path)
|
|
||||||
else:
|
|
||||||
assert_never(platform)
|
|
||||||
finally:
|
finally:
|
||||||
# avoid https://github.com/python/cpython/issues/86962 by performing
|
# avoid https://github.com/python/cpython/issues/86962 by performing
|
||||||
# cleanup manually
|
# cleanup manually
|
||||||
@@ -354,25 +370,9 @@ def print_preamble(platform: str, options: Options, identifiers: list[str]) -> N
|
|||||||
|
|
||||||
|
|
||||||
def get_build_identifiers(
|
def get_build_identifiers(
|
||||||
platform: PlatformName, build_selector: BuildSelector, architectures: Set[Architecture]
|
platform_module: PlatformModule, build_selector: BuildSelector, architectures: Set[Architecture]
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
python_configurations: Sequence[GenericPythonConfiguration]
|
python_configurations = platform_module.get_python_configurations(build_selector, architectures)
|
||||||
|
|
||||||
if platform == "linux":
|
|
||||||
python_configurations = cibuildwheel.linux.get_python_configurations(
|
|
||||||
build_selector, architectures
|
|
||||||
)
|
|
||||||
elif platform == "windows":
|
|
||||||
python_configurations = cibuildwheel.windows.get_python_configurations(
|
|
||||||
build_selector, architectures
|
|
||||||
)
|
|
||||||
elif platform == "macos":
|
|
||||||
python_configurations = cibuildwheel.macos.get_python_configurations(
|
|
||||||
build_selector, architectures
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
assert_never(platform)
|
|
||||||
|
|
||||||
return [config.identifier for config in python_configurations]
|
return [config.identifier for config in python_configurations]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from cibuildwheel.__main__ import get_build_identifiers
|
from cibuildwheel.__main__ import get_build_identifiers, get_platform_module
|
||||||
from cibuildwheel.bashlex_eval import local_environment_executor
|
from cibuildwheel.bashlex_eval import local_environment_executor
|
||||||
from cibuildwheel.environment import parse_environment
|
from cibuildwheel.environment import parse_environment
|
||||||
from cibuildwheel.options import (
|
from cibuildwheel.options import (
|
||||||
@@ -49,8 +49,9 @@ def test_options_1(tmp_path, monkeypatch):
|
|||||||
|
|
||||||
options = Options(platform="linux", command_line_arguments=args, env={})
|
options = Options(platform="linux", command_line_arguments=args, env={})
|
||||||
|
|
||||||
|
module = get_platform_module("linux")
|
||||||
identifiers = get_build_identifiers(
|
identifiers = get_build_identifiers(
|
||||||
platform="linux",
|
platform_module=module,
|
||||||
build_selector=options.globals.build_selector,
|
build_selector=options.globals.build_selector,
|
||||||
architectures=options.globals.architectures,
|
architectures=options.globals.architectures,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user