Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add formatted indentifier printout #1262

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ inputs:
description: 'File containing the config, defaults to {package}/pyproject.toml'
required: false
default: ''
print-build-identifiers:
description: 'Print build identifiers and exit. Set id: to access these in a later step'
required: false
default: ''
branding:
icon: package
color: yellow
Expand All @@ -36,5 +40,6 @@ runs:
${{ inputs.package-dir }}
--output-dir ${{ inputs.output-dir }}
--config-file "${{ inputs.config-file }}"
--print-build-identifiers "${{ inputs.print-build-identifiers }}"
2>&1
shell: bash
34 changes: 31 additions & 3 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ 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}, {os}
(manylinux / musllinux / macos / windows), and {impl} (CPython,
PyPy). Default: {identifier}.
""",
)

parser.add_argument(
Expand Down Expand Up @@ -210,7 +218,27 @@ def build_in_directory(args: CommandLineArguments) -> None:

if args.print_build_identifiers:
for identifier in identifiers:
print(identifier)
py_ver, os_plat = identifier.split("-")
impl = py_ver[:2]
version = f"{py_ver[2]}.{py_ver[3:]}"

if os_plat == "win32":
os_ = "win32"
arch = "x86"
else:
os_, arch = os_plat.split("_", maxsplit=1)
if os_ == "win32":
arch = arch.upper()

print(
args.print_build_identifiers.format(
identifier=identifier,
arch=arch,
version=version,
os=os_,
impl="CPython" if impl == "cp" else "PyPy",
)
)
sys.exit(0)

# Add CIBUILDWHEEL environment variable
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
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