Repository navigation
Conversation
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.
hjmjohnson
left a comment
There was a problem hiding this comment.
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 underbuild/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:
- Add
-ssw("compresses files open for writing by another applications") and keep== 0. This fixes the case in the PR body. - To find out what a warning was, keep 7-Zip's output: call
run_command(..., stream=True)directly or letecho_check_callreturn theCompletedProcess, then print theWARNING:lines before falling back._run_streamingalready keeps every line, butecho_check_callthrows 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] | |||
There was a problem hiding this comment.
should-fix: include files held open for writing, which fixes the run2.log case without accepting other warnings.
| cmd += ["-xr!" + pattern.replace("/", "\\") for pattern in ARCHIVE_EXCLUDES] | |
| cmd += ["-ssw"] | |
| cmd += ["-xr!" + pattern.replace("/", "\\") for pattern in ARCHIVE_EXCLUDES] |
There was a problem hiding this comment.
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.
| # 1 is a warning, such as a file another process holds open. | ||
| if return_status in (0, 1): |
There was a problem hiding this comment.
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.
| # 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 |
There was a problem hiding this comment.
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:
| return status | |
| (windows_builder.build_dir_root / "ITKPythonBuilds-windows.zip").write_bytes(b"7z") | |
| return status |
| 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() |
There was a problem hiding this comment.
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.
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_tarballdeleted that archive and wrote the zip fallback instead.How it showed up
The
release-wheelsoutput was redirected torun2.loginside 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
Checklist
pre-commit run --all-files), except prettierdocs/)BUG:,COMP:,DOC:,ENH:,PERF:,STYLE:)Platform(s) Tested
AI assistance
🤖 Generated with Claude Code