Skip to content

Commit

Permalink
feat: add formatted indentifier printout
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 3a46bde commit c80aa97
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 39 deletions.
51 changes: 27 additions & 24 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ def main() -> None:

parser.add_argument(
"--print-build-identifiers",
action="store_true",
help="Print the build identifiers matched by the current invocation and exit.",
action="store",
const="{identifier}",
nargs="?",
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}.
""",
)

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

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

if args.print_build_identifiers:
for identifier in identifiers:
print(identifier)
if args.print_build_identifiers is not None:
for config in configs:
print(
args.print_build_identifiers.format(
identifier=config.identifier,
arch=config.architecture.name,
version=config.version,
)
)
sys.exit(0)

identifiers = [config.identifier for config in configs]

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

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


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

if platform == "linux":
python_configurations = cibuildwheel.linux.get_python_configurations(
build_selector, architectures
)
return cibuildwheel.linux.get_python_configurations(build_selector, architectures)
elif platform == "windows":
python_configurations = cibuildwheel.windows.get_python_configurations(
build_selector, architectures
)
return cibuildwheel.windows.get_python_configurations(build_selector, architectures)
elif platform == "macos":
python_configurations = cibuildwheel.macos.get_python_configurations(
build_selector, architectures
)
return 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: 4 additions & 0 deletions cibuildwheel/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ 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: 4 additions & 0 deletions cibuildwheel/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ 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
2 changes: 1 addition & 1 deletion cibuildwheel/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CommandLineArguments:
output_dir: Path
config_file: str
package_dir: Path
print_build_identifiers: bool
print_build_identifiers: str | None
allow_empty: bool
prerelease_pythons: bool

Expand Down
16 changes: 9 additions & 7 deletions cibuildwheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
"split_config_settings",
]

resources_dir: Final = Path(__file__).parent / "resources"
resources_dir: Final[Path] = Path(__file__).parent / "resources"

install_certifi_script: Final = resources_dir / "install_certifi.py"
install_certifi_script: Final[Path] = resources_dir / "install_certifi.py"

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

MANYLINUX_ARCHS: Final = (
MANYLINUX_ARCHS: Final[tuple[str, ...]] = (
"x86_64",
"i686",
"pypy_x86_64",
Expand All @@ -80,18 +80,20 @@
"pypy_i686",
)

MUSLLINUX_ARCHS: Final = (
MUSLLINUX_ARCHS: Final[tuple[str, ...]] = (
"x86_64",
"i686",
"aarch64",
"ppc64le",
"s390x",
)

DEFAULT_CIBW_CACHE_PATH: Final = user_cache_path(appname="cibuildwheel", appauthor="pypa")
CIBW_CACHE_PATH: Final = Path(os.environ.get("CIBW_CACHE_PATH", DEFAULT_CIBW_CACHE_PATH)).resolve()
DEFAULT_CIBW_CACHE_PATH: Final[Path] = user_cache_path(appname="cibuildwheel", appauthor="pypa")
CIBW_CACHE_PATH: Final[Path] = Path(
os.environ.get("CIBW_CACHE_PATH", DEFAULT_CIBW_CACHE_PATH)
).resolve()

IS_WIN: Final = sys.platform.startswith("win")
IS_WIN: Final[bool] = sys.platform.startswith("win")


@overload
Expand Down
4 changes: 4 additions & 0 deletions cibuildwheel/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ 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: 9 additions & 6 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_identifiers
from cibuildwheel.__main__ import get_build_configs
from cibuildwheel.environment import parse_environment
from cibuildwheel.options import Options, _get_pinned_container_images

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

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

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

override_display = """\
test_command: 'pyproject'
Expand Down
2 changes: 1 addition & 1 deletion unit_test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_default_command_line_arguments() -> CommandLineArguments:
output_dir=Path("wheelhouse"),
package_dir=Path("."),
prerelease_pythons=False,
print_build_identifiers=False,
print_build_identifiers=None,
)

return defaults

0 comments on commit c80aa97

Please sign in to comment.