Skip to content

Keep the 7-Zip cache archive when 7-Zip only warns - #321

Draft
dzenanz wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
dzenanz:windows-7zip-warnings
Draft

dzenanz wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
dzenanz:windows-7zip-warnings

Conversation

@dzenanz

@dzenanz dzenanz commented Nov 26, 2026

Copy link
Copy Markdown
Member

It is a philosophical question whether we should merge this. Opening it for discussion. AI description below:

Summary

Keep the Windows cache archive that 7-Zip wrote when it exits 1, which means warnings only. Until now, build_tarball deleted that archive and wrote the zip fallback instead.

How it showed up

The release-wheels output was redirected to run2.log inside the ITKPythonPackage checkout, which is one of the archived folders. 7-Zip could not read that open file. It wrote the rest of the archive (279 MiB, 7z), warned, and exited 1. The build then wrote the Python zip fallback (470 MB, zip, a different file count) over it. Step 07 still reported "completed".

Type of Change

  • Bug fix
  • New feature / enhancement
  • Refactor / cleanup
  • Docs / CI only

Checklist

  • Pre-commit hooks pass locally (pre-commit run --all-files), except prettier
  • Tested wheel build on affected platform(s) (Linux / macOS / Windows)
  • Docs updated if behavior changed (docs/)
  • Commit messages use ITK prefixes (BUG:, COMP:, DOC:, ENH:, PERF:, STYLE:)

Platform(s) Tested

  • Linux x86_64 (manylinux)
  • Linux aarch64 (manylinux)
  • macOS arm64
  • Windows x86_64 (test suite: 498 passed, 6 skipped)
AI assistance
  • Tool: Claude Code (claude-opus-5-5)
  • Role: diagnosed the fallback from the build log and the archive on disk, and wrote the fix and its test

🤖 Generated with Claude Code

7-Zip exits 1 for warnings, such as a file another process holds open
(a build log redirected into the checkout). build_tarball treated that
as failure, deleted the complete archive, and wrote the zip fallback
instead, with a different format and file set.
@dzenanz
dzenanz requested a review from hjmjohnson November 26, 2026 13:58

@hjmjohnson hjmjohnson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To answer the question you raised: I'd rather not accept exit code 1. -ssw fixes the incident you hit, and exit 1 can stand for several worse failures than a skipped log.

7-Zip documents exit code 1 as "Warning (Non fatal error(s)) ... one or more files were locked by some other application, so they were not compressed". Without -sse, it also skips input files it cannot open. So exit 1 covers all of these:

  • a file another process holds open for writing (your run2.log): harmless;
  • a .lib, .pyd, or header under build/ that an indexer, antivirus scan, or leftover compiler process holds: the module build fails much later, far from the cause;
  • access denied on a directory: the whole subtree is missing;
  • a file deleted between 7-Zip's scan and its read;
  • a missing archive root (ITK/, build/, or the IPP checkout): 7-Zip warns that it cannot find the file, and the archive is missing that whole root.

With this change, every one of these publishes an incomplete cache and step 07 still reports "completed". The old fallback had the right content. It read run2.log because Python's open() on Windows shares write access and 7-Zip by default does not. The fallback's only cost was a bigger zip.

Why a file was open at all: the build finishes compiling before step 07, and none of the scripts write a log into the archived folders. Your run2.log was the output of this same build, redirected into the checkout, which is one of the archive roots. So the archive step was reading its own log while it was still being written. A log doesn't belong in the build cache in any case, so I'd also add "*.log" to ARCHIVE_EXCLUDES (scripts/windows_build_python_instance.py:18), or note in the docs that redirected output should go outside the checkout. Other ways to hit this (a second build in the same tree, an editor or indexer holding a file) are rare, and they are the cases worth hearing about.

Suggested direction, with details inline:

  1. Add -ssw ("compresses files open for writing by another applications") and keep == 0. This fixes the case in the PR body.
  2. To find out what a warning was, keep 7-Zip's output: call run_command(..., stream=True) directly or let echo_check_call return the CompletedProcess, then print the WARNING: lines before falling back. _run_streaming already keeps every line, but echo_check_call throws them away.

Not run on Windows: the 7-Zip exit codes and -ssw come from the 7-Zip docs, and the file-sharing difference and the missing-root warning are reasoned from the code. A Windows check that would settle it: hold a file open with $f=[IO.File]::Open('C:\\P\\IPP\\x.log','Append','Write','Read'), then run 7z a with and without -ssw.

Also, the PR body says pre-commit passes "except prettier"; AGENTS.md asks that pre-commit run --all-files pass on the pushed tip.

@@ -222,7 +222,8 @@ def build_tarball(self) -> None:
]
cmd += ["-xr!" + pattern.replace("/", "\\") for pattern in ARCHIVE_EXCLUDES]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix: include files held open for writing, which fixes the run2.log case without accepting other warnings.

Suggested change
cmd += ["-xr!" + pattern.replace("/", "\\") for pattern in ARCHIVE_EXCLUDES]
cmd += ["-ssw"]
cmd += ["-xr!" + pattern.replace("/", "\\") for pattern in ARCHIVE_EXCLUDES]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be explicit about my preference: I'd rather take -ssw than accept exit code 1. -ssw fixes the open-log case directly, and keeping == 0 means any other warning (a locked build file, a missing root) still reaches the fallback rather than publishing an incomplete cache.

Comment on lines +225 to +226
# 1 is a warning, such as a file another process holds open.
if return_status in (0, 1):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix: with -ssw, exit 1 means something else went wrong (an unreadable file, access denied, a missing root), so it should still go to the fallback.

Suggested change
# 1 is a warning, such as a file another process holds open.
if return_status in (0, 1):
if return_status == 0:

If you'd still rather keep a warned archive, print the skipped paths from the captured output first, so the log says which files are missing (see the review body).

def fake_call(cmd: Sequence[object], *args: object, **kwargs: object) -> int:
captured["cmd"] = [str(c) for c in cmd]
return 0
return status

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix: the fake never writes the archive, so the test below can't tell "kept" from "never written". Have it write a marker so the test can check that the archive survives:

Suggested change
return status
(windows_builder.build_dir_root / "ITKPythonBuilds-windows.zip").write_bytes(b"7z")
return status

Comment on lines +275 to +280
def test_seven_zip_warnings_keep_its_archive(
tmp_path: Path, windows_builder: WindowsBuildPythonInstance
) -> None:
"""Exit code 1 (e.g. a locked log file) must not start the zip fallback."""
_run_build_tarball(windows_builder, tmp_path, status=1)
assert not (windows_builder.build_dir_root / "ITKPythonBuilds-windows.zip").exists()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix: as written, this asserts the archive does not exist, the opposite of its name. With the marker above, assert the bytes survive at status 0. Add a test that status 1 and 2 (or 1 alone, if you take the -ssw route) still run the zip fallback, since that boundary is what this PR moves. If -ssw goes in, assert it is in the command next to test_seven_zip_command_carries_no_recursive_flag.

@hjmjohnson
hjmjohnson marked this pull request as draft November 26, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants