Skip to content

Commit

Permalink
refactor: revert to fewer changes
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Sep 8, 2022
1 parent 6d984e3 commit da8d18c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
47 changes: 32 additions & 15 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def main() -> None:
help="""
Print the build identifiers matched by the current invocation and
exit. Optionally, specify a format string to print the identifiers.
Available replacements are {identifier}, {arch}, {version}. Default: {identifier}.
Available replacements are {identifier}, {arch}, {version}, {os}
(manylinux / musllinux / macos / windows), and {impl} (CPython,
PyPy). Default: {identifier}.
""",
)

Expand Down Expand Up @@ -208,25 +210,29 @@ def build_in_directory(args: CommandLineArguments) -> None:
print(msg, file=sys.stderr)
sys.exit(2)

configs = get_build_configs(
identifiers = get_build_identifiers(
platform=platform,
build_selector=options.globals.build_selector,
architectures=options.globals.architectures,
)

if args.print_build_identifiers is not None:
for config in configs:
for identifier in identifiers:
py_ver, os_plat = identifier.split("-")
impl = py_ver[:2]
version = f"{py_ver[2]}.{py_ver[3:]}"
os_, arch = os_plat.split("_", maxsplit=1)
print(
args.print_build_identifiers.format(
identifier=config.identifier,
arch=config.architecture.name,
version=config.version,
identifier=identifier,
arch=arch,
version=version,
os=os_,
impl="CPython" if impl == "cp" else "PyPy",
)
)
sys.exit(0)

identifiers = [config.identifier for config in configs]

# Add CIBUILDWHEEL environment variable
os.environ["CIBUILDWHEEL"] = "1"

Expand Down Expand Up @@ -308,21 +314,32 @@ def print_preamble(platform: str, options: Options, identifiers: list[str]) -> N
print("\nHere we go!\n")


def get_build_configs(
def get_build_identifiers(
platform: PlatformName, build_selector: BuildSelector, architectures: set[Architecture]
) -> list[cibuildwheel.linux.PythonConfiguration] | list[
cibuildwheel.windows.PythonConfiguration
] | list[cibuildwheel.macos.PythonConfiguration]:
) -> list[str]:
python_configurations: (
list[cibuildwheel.linux.PythonConfiguration]
| list[cibuildwheel.windows.PythonConfiguration]
| list[cibuildwheel.macos.PythonConfiguration]
)

if platform == "linux":
return cibuildwheel.linux.get_python_configurations(build_selector, architectures)
python_configurations = cibuildwheel.linux.get_python_configurations(
build_selector, architectures
)
elif platform == "windows":
return cibuildwheel.windows.get_python_configurations(build_selector, architectures)
python_configurations = cibuildwheel.windows.get_python_configurations(
build_selector, architectures
)
elif platform == "macos":
return cibuildwheel.macos.get_python_configurations(build_selector, architectures)
python_configurations = cibuildwheel.macos.get_python_configurations(
build_selector, architectures
)
else:
assert_never(platform)

return [config.identifier for config in python_configurations]


def detect_warnings(*, options: Options, identifiers: list[str]) -> list[str]:
warnings = []
Expand Down
4 changes: 0 additions & 4 deletions cibuildwheel/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class PythonConfiguration:
def path(self) -> PurePosixPath:
return PurePosixPath(self.path_str)

@property
def architecture(self) -> Architecture:
return Architecture[self.identifier.split("_", maxsplit=1)[-1]]


@dataclass(frozen=True)
class BuildStep:
Expand Down
4 changes: 0 additions & 4 deletions cibuildwheel/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ class PythonConfiguration:
identifier: str
url: str

@property
def architecture(self) -> Architecture:
return Architecture[self.identifier.split("_", maxsplit=1)[-1]]


def get_python_configurations(
build_selector: BuildSelector, architectures: set[Architecture]
Expand Down
4 changes: 0 additions & 4 deletions cibuildwheel/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ class PythonConfiguration:
identifier: str
url: str | None = None

@property
def architecture(self) -> Architecture:
return Architecture[self.identifier.split("_", maxsplit=1)[-1]]


def get_python_configurations(
build_selector: BuildSelector,
Expand Down
15 changes: 6 additions & 9 deletions unit_test/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from cibuildwheel.__main__ import get_build_configs
from cibuildwheel.__main__ import get_build_identifiers
from cibuildwheel.environment import parse_environment
from cibuildwheel.options import Options, _get_pinned_container_images

Expand Down Expand Up @@ -43,14 +43,11 @@ def test_options_1(tmp_path, monkeypatch):

options = Options(platform="linux", command_line_arguments=args)

identifiers = [
c.identifier
for c in get_build_configs(
platform="linux",
build_selector=options.globals.build_selector,
architectures=options.globals.architectures,
)
]
identifiers = get_build_identifiers(
platform="linux",
build_selector=options.globals.build_selector,
architectures=options.globals.architectures,
)

override_display = """\
test_command: 'pyproject'
Expand Down

0 comments on commit da8d18c

Please sign in to comment.