Merge pull request #1460 from hoodmane/chore-compute-platform

This commit is contained in:
Joe Rickerby
2023-04-10 22:22:04 +02:00
committed by GitHub
+45 -36
View File
@@ -173,44 +173,22 @@ def main() -> None:
log.warning(f"Can't delete temporary folder '{temp_dir}'") log.warning(f"Can't delete temporary folder '{temp_dir}'")
def build_in_directory(args: CommandLineArguments) -> None: def _compute_platform_only(only: str) -> PlatformName:
platform_option_value = args.platform or os.environ.get("CIBW_PLATFORM", "auto") if "linux_" in only:
platform: PlatformName return "linux"
if "macosx_" in only:
if args.only: return "macos"
if "linux_" in args.only: if "win_" in only or "win32" in only:
platform = "linux" return "windows"
elif "macosx_" in args.only:
platform = "macos"
elif "win_" in args.only or "win32" in args.only:
platform = "windows"
else:
print( print(
f"Invalid --only='{args.only}', must be a build selector with a known platform", f"Invalid --only='{only}', must be a build selector with a known platform",
file=sys.stderr, file=sys.stderr,
) )
sys.exit(2) sys.exit(2)
if args.platform is not None:
print(
"--platform cannot be specified with --only, it is computed from --only",
file=sys.stderr,
)
sys.exit(2)
if args.archs is not None:
print(
"--arch cannot be specified with --only, it is computed from --only",
file=sys.stderr,
)
sys.exit(2)
elif platform_option_value != "auto":
if platform_option_value not in PLATFORMS:
print(f"cibuildwheel: Unsupported platform: {platform_option_value}", file=sys.stderr)
sys.exit(2)
platform = typing.cast(PlatformName, platform_option_value)
else: def _compute_platform_ci() -> PlatformName:
ci_provider = detect_ci_provider() if detect_ci_provider() is None:
if ci_provider is None:
print( print(
textwrap.dedent( textwrap.dedent(
""" """
@@ -224,11 +202,11 @@ def build_in_directory(args: CommandLineArguments) -> None:
) )
sys.exit(2) sys.exit(2)
if sys.platform.startswith("linux"): if sys.platform.startswith("linux"):
platform = "linux" return "linux"
elif sys.platform == "darwin": elif sys.platform == "darwin":
platform = "macos" return "macos"
elif sys.platform == "win32": elif sys.platform == "win32":
platform = "windows" return "windows"
else: else:
print( print(
'cibuildwheel: Unable to detect platform from "sys.platform" in a CI environment. You can run ' 'cibuildwheel: Unable to detect platform from "sys.platform" in a CI environment. You can run '
@@ -237,6 +215,37 @@ def build_in_directory(args: CommandLineArguments) -> None:
) )
sys.exit(2) sys.exit(2)
def _compute_platform(args: CommandLineArguments) -> PlatformName:
platform_option_value = args.platform or os.environ.get("CIBW_PLATFORM", "auto")
if args.only and args.platform is not None:
print(
"--platform cannot be specified with --only, it is computed from --only",
file=sys.stderr,
)
sys.exit(2)
if args.only and args.archs is not None:
print(
"--arch cannot be specified with --only, it is computed from --only",
file=sys.stderr,
)
sys.exit(2)
if platform_option_value not in PLATFORMS | {"auto"}:
print(f"cibuildwheel: Unsupported platform: {platform_option_value}", file=sys.stderr)
sys.exit(2)
if args.only:
return _compute_platform_only(args.only)
elif platform_option_value != "auto":
return typing.cast(PlatformName, platform_option_value)
return _compute_platform_ci()
def build_in_directory(args: CommandLineArguments) -> None:
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)
package_dir = options.globals.package_dir package_dir = options.globals.package_dir