Skip to content

Commit

Permalink
Set the defualt build_frontend to be "default" (which is still "pip")
Browse files Browse the repository at this point in the history
Instead of using pip as the default, set it to default. This way
each platform can choose independently what to do as the default
behavior.

This is intended as part of adding Pyodide support. Pyodide cannot
use pip as the build frontend. It always uses a modified pypa/build.
So if the build_frontend is explicitly set to pip we want to raise
an error. But if it's unset, then we should be able to tell and just
do what we want.
  • Loading branch information
hoodmane committed Apr 7, 2023
1 parent d018570 commit 3f039b7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
10 changes: 6 additions & 4 deletions cibuildwheel/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .util import (
AlreadyBuiltWheelError,
BuildSelector,
build_frontend_or_default,
NonPlatformWheelError,
find_compatible_wheel,
get_build_verbosity_extra_flags,
Expand Down Expand Up @@ -143,6 +144,7 @@ def build_in_container(
container_package_dir: PurePath,
) -> None:
container_output_dir = PurePosixPath("/output")
build_frontend = build_frontend_or_default(options.build_frontend, "pip")

check_all_python_exist(platform_configs=platform_configs, container=container)

Expand Down Expand Up @@ -242,10 +244,10 @@ def build_in_container(

verbosity_flags = get_build_verbosity_extra_flags(build_options.build_verbosity)
extra_flags = split_config_settings(
build_options.config_settings, build_options.build_frontend
build_options.config_settings, build_frontend
)

if build_options.build_frontend == "pip":
if build_frontend == "pip":
extra_flags += verbosity_flags
container.call(
[
Expand All @@ -260,7 +262,7 @@ def build_in_container(
],
env=env,
)
elif build_options.build_frontend == "build":
elif build_frontend == "build":
verbosity_setting = " ".join(verbosity_flags)
extra_flags += (f"--config-setting={verbosity_setting}",)
container.call(
Expand All @@ -276,7 +278,7 @@ def build_in_container(
env=env,
)
else:
assert_never(build_options.build_frontend)
assert_never(build_frontend)

built_wheel = container.glob(built_wheel_dir, "*.whl")[0]

Expand Down
14 changes: 9 additions & 5 deletions cibuildwheel/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
AlreadyBuiltWheelError,
BuildFrontend,
BuildSelector,
build_frontend_or_default,
NonPlatformWheelError,
call,
detect_ci_provider,
Expand Down Expand Up @@ -311,6 +312,9 @@ def build(options: Options, tmp_path: Path) -> None:
options.globals.build_selector, options.globals.architectures
)

build_frontend = build_frontend_or_default(options.build_frontend, "pip")


if not python_configurations:
return

Expand Down Expand Up @@ -353,7 +357,7 @@ def build(options: Options, tmp_path: Path) -> None:
config,
dependency_constraint_flags,
build_options.environment,
build_options.build_frontend,
build_frontend,
)

compatible_wheel = find_compatible_wheel(built_wheels, config.identifier)
Expand All @@ -376,10 +380,10 @@ def build(options: Options, tmp_path: Path) -> None:

verbosity_flags = get_build_verbosity_extra_flags(build_options.build_verbosity)
extra_flags = split_config_settings(
build_options.config_settings, build_options.build_frontend
build_options.config_settings, build_frontend
)

if build_options.build_frontend == "pip":
if build_frontend == "pip":
extra_flags += verbosity_flags
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
# see https://github.com/pypa/cibuildwheel/pull/369
Expand All @@ -394,7 +398,7 @@ def build(options: Options, tmp_path: Path) -> None:
*extra_flags,
env=env,
)
elif build_options.build_frontend == "build":
elif build_frontend == "build":
verbosity_setting = " ".join(verbosity_flags)
extra_flags += (f"--config-setting={verbosity_setting}",)
build_env = env.copy()
Expand All @@ -417,7 +421,7 @@ def build(options: Options, tmp_path: Path) -> None:
env=build_env,
)
else:
assert_never(build_options.build_frontend)
assert_never(build_frontend)

built_wheel = next(built_wheel_dir.glob("*.whl"))

Expand Down
6 changes: 4 additions & 2 deletions cibuildwheel/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class BuildOptions:
test_requires: list[str]
test_extras: str
build_verbosity: int
build_frontend: BuildFrontend
build_frontend: BuildFrontend | Literal["default"]
config_settings: str

@property
Expand Down Expand Up @@ -499,11 +499,13 @@ def build_options(self, identifier: str | None) -> BuildOptions:
test_extras = self.reader.get("test-extras", sep=",")
build_verbosity_str = self.reader.get("build-verbosity")

build_frontend: BuildFrontend
build_frontend: BuildFrontend | Literal["default"]
if build_frontend_str == "build":
build_frontend = "build"
elif build_frontend_str == "pip":
build_frontend = "pip"
elif build_frontend_str == "default":
build_frontend = "default"
else:
msg = f"cibuildwheel: Unrecognised build frontend {build_frontend_str!r}, only 'pip' and 'build' are supported"
print(msg, file=sys.stderr)
Expand Down
2 changes: 1 addition & 1 deletion cibuildwheel/resources/defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip = ""
test-skip = ""

archs = ["auto"]
build-frontend = "pip"
build-frontend = "default"
config-settings = {}
dependency-versions = "pinned"
environment = {}
Expand Down
5 changes: 5 additions & 0 deletions cibuildwheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@

BuildFrontend = Literal["pip", "build"]

def build_frontend_or_default(setting: BuildFrontend | Literal["default"], default: BuildFrontend) -> BuildFrontend:
if setting == "default":
return default
return setting

MANYLINUX_ARCHS: Final[tuple[str, ...]] = (
"x86_64",
"i686",
Expand Down
12 changes: 7 additions & 5 deletions cibuildwheel/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
AlreadyBuiltWheelError,
BuildFrontend,
BuildSelector,
build_frontend_or_default,
NonPlatformWheelError,
call,
download,
Expand Down Expand Up @@ -347,6 +348,7 @@ def build(options: Options, tmp_path: Path) -> None:
python_configurations = get_python_configurations(
options.globals.build_selector, options.globals.architectures
)
build_frontend = build_frontend_or_default(options.build_frontend, "pip")

if not python_configurations:
return
Expand Down Expand Up @@ -387,7 +389,7 @@ def build(options: Options, tmp_path: Path) -> None:
config,
dependency_constraint_flags,
build_options.environment,
build_options.build_frontend,
build_frontend,
)

compatible_wheel = find_compatible_wheel(built_wheels, config.identifier)
Expand All @@ -413,10 +415,10 @@ def build(options: Options, tmp_path: Path) -> None:

verbosity_flags = get_build_verbosity_extra_flags(build_options.build_verbosity)
extra_flags = split_config_settings(
build_options.config_settings, build_options.build_frontend
build_options.config_settings, build_frontend
)

if build_options.build_frontend == "pip":
if build_frontend == "pip":
extra_flags += verbosity_flags
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
# see https://github.com/pypa/cibuildwheel/pull/369
Expand All @@ -431,7 +433,7 @@ def build(options: Options, tmp_path: Path) -> None:
*extra_flags,
env=env,
)
elif build_options.build_frontend == "build":
elif build_frontend == "build":
verbosity_setting = " ".join(verbosity_flags)
extra_flags += (f"--config-setting={verbosity_setting}",)
build_env = env.copy()
Expand Down Expand Up @@ -464,7 +466,7 @@ def build(options: Options, tmp_path: Path) -> None:
env=build_env,
)
else:
assert_never(build_options.build_frontend)
assert_never(build_frontend)

built_wheel = next(built_wheel_dir.glob("*.whl"))

Expand Down

0 comments on commit 3f039b7

Please sign in to comment.