Skip to content

Commit db6b675

Browse files
committed
refactor: new summary table
1 parent 4a4812f commit db6b675

File tree

7 files changed

+62
-53
lines changed

7 files changed

+62
-53
lines changed

action.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,3 @@ runs:
8989
${{ inputs.only != '' && format('--only "{0}"', inputs.only) || ''}}
9090
shell: pwsh
9191
if: runner.os == 'Windows'
92-
93-
- run: |
94-
# Prepare summary
95-
"${{ steps.python.outputs.python-path }}" -u << "EOF"
96-
import os
97-
from pathlib import Path
98-
99-
output_dir = Path("${{ inputs.output-dir }}" or "wheelhouse")
100-
101-
with Path(os.environ["GITHUB_STEP_SUMMARY"]).open("w", encoding="utf-8") as f:
102-
print("## 🎡: files in output directory", file=f)
103-
print(file=f)
104-
for item in sorted(output_dir.iterdir()):
105-
if item.is_file():
106-
size_mb = item.stat().st_size / 1024**2
107-
print(f"* `{item}` - {size_mb:.2f} MB", file=f)
108-
else:
109-
print(f"* `{item.name}/`", file=f)
110-
print(file=f)
111-
EOF
112-
shell: bash

cibuildwheel/__main__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,10 @@ def print_new_wheels(msg: str, output_dir: Path) -> Generator[None, None, None]:
308308
if not new_contents:
309309
return
310310

311-
max_name_len = max(len(f.name) for f in new_contents)
312-
max_size_len = max(len(f.size) for f in new_contents)
313311
n = len(new_contents)
314312
s = time.time() - start_time
315313
m = s / 60
316-
print(
317-
msg.format(n=n, s=s, m=m),
318-
*sorted(
319-
f" {f.name:<{max_name_len}s} {f.size:>{max_size_len}s} kB" for f in new_contents
320-
),
321-
sep="\n",
322-
)
314+
print(msg.format(n=n, s=s, m=m))
323315

324316

325317
def build_in_directory(args: CommandLineArguments) -> None:
@@ -382,8 +374,9 @@ def build_in_directory(args: CommandLineArguments) -> None:
382374

383375
tmp_path = Path(mkdtemp(prefix="cibw-run-")).resolve(strict=True)
384376
try:
385-
with print_new_wheels("\n{n} wheels produced in {m:.0f} minutes:", output_dir):
377+
with print_new_wheels("\n{n} wheels produced in {m:.0f} minutes", output_dir):
386378
platform_module.build(options, tmp_path)
379+
log.print_summary()
387380
finally:
388381
# avoid https://github.com/python/cpython/issues/86962 by performing
389382
# cleanup manually

cibuildwheel/logger.py

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import re
44
import sys
55
import time
6-
from typing import IO, AnyStr, Final
6+
from pathlib import Path
7+
from typing import IO, AnyStr, Final, Literal
78

89
from .ci import CIProvider, detect_ci_provider
910

@@ -70,13 +71,15 @@ def __init__(self, *, unicode: bool) -> None:
7071

7172

7273
class Logger:
73-
fold_mode: str
74+
fold_mode: Literal["azure", "github", "travis", "disabled"]
7475
colors_enabled: bool
7576
unicode_enabled: bool
7677
active_build_identifier: str | None = None
7778
build_start_time: float | None = None
7879
step_start_time: float | None = None
7980
active_fold_group_name: str | None = None
81+
summary: list[tuple[str, Path | None, float]]
82+
summary_mode: Literal["github", "generic"]
8083

8184
def __init__(self) -> None:
8285
if sys.platform == "win32" and hasattr(sys.stdout, "reconfigure"):
@@ -88,25 +91,33 @@ def __init__(self) -> None:
8891

8992
ci_provider = detect_ci_provider()
9093

91-
if ci_provider == CIProvider.azure_pipelines:
92-
self.fold_mode = "azure"
93-
self.colors_enabled = True
94+
match ci_provider:
95+
case CIProvider.azure_pipelines:
96+
self.fold_mode = "azure"
97+
self.colors_enabled = True
98+
self.summary_mode = "generic"
9499

95-
elif ci_provider == CIProvider.github_actions:
96-
self.fold_mode = "github"
97-
self.colors_enabled = True
100+
case CIProvider.github_actions:
101+
self.fold_mode = "github"
102+
self.colors_enabled = True
103+
self.summary_mode = "github"
98104

99-
elif ci_provider == CIProvider.travis_ci:
100-
self.fold_mode = "travis"
101-
self.colors_enabled = True
105+
case CIProvider.travis_ci:
106+
self.fold_mode = "travis"
107+
self.colors_enabled = True
108+
self.summary_mode = "generic"
102109

103-
elif ci_provider == CIProvider.appveyor:
104-
self.fold_mode = "disabled"
105-
self.colors_enabled = True
110+
case CIProvider.appveyor:
111+
self.fold_mode = "disabled"
112+
self.colors_enabled = True
113+
self.summary_mode = "generic"
106114

107-
else:
108-
self.fold_mode = "disabled"
109-
self.colors_enabled = file_supports_color(sys.stdout)
115+
case _:
116+
self.fold_mode = "disabled"
117+
self.colors_enabled = file_supports_color(sys.stdout)
118+
self.summary_mode = "generic"
119+
120+
self.summary = []
110121

111122
def build_start(self, identifier: str) -> None:
112123
self.step_end()
@@ -120,7 +131,7 @@ def build_start(self, identifier: str) -> None:
120131
self.build_start_time = time.time()
121132
self.active_build_identifier = identifier
122133

123-
def build_end(self) -> None:
134+
def build_end(self, filename: Path | None) -> None:
124135
assert self.build_start_time is not None
125136
assert self.active_build_identifier is not None
126137
self.step_end()
@@ -133,6 +144,8 @@ def build_end(self) -> None:
133144
print(
134145
f"{c.green}{s.done} {c.end}{self.active_build_identifier} finished in {duration:.2f}s"
135146
)
147+
self.summary.append((self.active_build_identifier, filename, duration))
148+
136149
self.build_start_time = None
137150
self.active_build_identifier = None
138151

@@ -183,6 +196,24 @@ def error(self, error: BaseException | str) -> None:
183196
c = self.colors
184197
print(f"cibuildwheel: {c.bright_red}error{c.end}: {error}\n", file=sys.stderr)
185198

199+
def print_summary(self) -> None:
200+
summary = "## 🎡: Wheels\n\n| Identifier | Wheel | Size | Time |\n|===|===|===|===|\n"
201+
for ident, filename, duration in self.summary:
202+
if filename:
203+
size_mb = filename.stat().st_size / 1024**2
204+
summary += f"| {ident} | {filename.name} | {size_mb:.2f} MB | {duration} |"
205+
else:
206+
summary += f"| {ident} | test only | --- | {duration} |"
207+
208+
match self.summary_mode:
209+
case "github":
210+
Path(os.environ["GITHUB_STEP_SUMMARY"]).write_text(summary, encoding="utf-8")
211+
print(summary)
212+
case _:
213+
print(summary)
214+
215+
self.summary = []
216+
186217
@property
187218
def step_active(self) -> bool:
188219
return self.step_start_time is not None

cibuildwheel/platforms/ios.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ def build(options: Options, tmp_path: Path) -> None:
671671
log.step_end()
672672

673673
# We're all done here; move it to output (overwrite existing)
674+
output_wheel: Path | None = None
674675
if compatible_wheel is None:
675676
output_wheel = build_options.output_dir.joinpath(built_wheel.name)
676677
moved_wheel = move_file(built_wheel, output_wheel)
@@ -683,7 +684,7 @@ def build(options: Options, tmp_path: Path) -> None:
683684
# Clean up
684685
shutil.rmtree(identifier_tmp_dir)
685686

686-
log.build_end()
687+
log.build_end(output_wheel)
687688
except subprocess.CalledProcessError as error:
688689
msg = f"Command {error.cmd} failed with code {error.returncode}. {error.stdout or ''}"
689690
raise errors.FatalError(msg) from error

cibuildwheel/platforms/linux.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,17 @@ def build_in_container(
418418
container.call(["rm", "-rf", testing_temp_dir])
419419

420420
# move repaired wheels to output
421+
# TODO: can this still output multiple wheels? I though it was just multiple tags
422+
output_wheel: Path | None = None
421423
if compatible_wheel is None:
422424
container.call(["mkdir", "-p", container_output_dir])
423425
container.call(["mv", *repaired_wheels, container_output_dir])
424426
built_wheels.extend(
425427
container_output_dir / repaired_wheel.name for repaired_wheel in repaired_wheels
426428
)
429+
output_wheel = options.globals.output_dir / repaired_wheels[0].name
427430

428-
log.build_end()
431+
log.build_end(output_wheel)
429432

430433
log.step("Copying wheels back to host...")
431434
# copy the output back into the host

cibuildwheel/platforms/macos.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ def build(options: Options, tmp_path: Path) -> None:
726726
shell_with_arch(test_command_prepared, cwd=test_cwd, env=virtualenv_env)
727727

728728
# we're all done here; move it to output (overwrite existing)
729+
output_wheel = None
729730
if compatible_wheel is None:
730731
output_wheel = build_options.output_dir.joinpath(repaired_wheel.name)
731732
moved_wheel = move_file(repaired_wheel, output_wheel)
@@ -738,7 +739,7 @@ def build(options: Options, tmp_path: Path) -> None:
738739
# clean up
739740
shutil.rmtree(identifier_tmp_dir)
740741

741-
log.build_end()
742+
log.build_end(output_wheel)
742743
except subprocess.CalledProcessError as error:
743744
msg = f"Command {error.cmd} failed with code {error.returncode}. {error.stdout or ''}"
744745
raise errors.FatalError(msg) from error

cibuildwheel/platforms/windows.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ def build(options: Options, tmp_path: Path) -> None:
607607
shell(test_command_prepared, cwd=test_cwd, env=virtualenv_env)
608608

609609
# we're all done here; move it to output (remove if already exists)
610+
output_wheel = None
610611
if compatible_wheel is None:
611612
output_wheel = build_options.output_dir.joinpath(repaired_wheel.name)
612613
moved_wheel = move_file(repaired_wheel, output_wheel)
@@ -621,7 +622,7 @@ def build(options: Options, tmp_path: Path) -> None:
621622
# don't want to abort a build because of that)
622623
shutil.rmtree(identifier_tmp_dir, ignore_errors=True)
623624

624-
log.build_end()
625+
log.build_end(output_wheel)
625626
except subprocess.CalledProcessError as error:
626627
msg = f"Command {error.cmd} failed with code {error.returncode}. {error.stdout or ''}"
627628
raise errors.FatalError(msg) from error

0 commit comments

Comments
 (0)