From 9b24bd9eb2c65f47aefe59d62a8e2066e6d1f092 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Wed, 20 Dec 2023 19:13:55 +0900 Subject: [PATCH] fix: demote the RECORD mismatch during patching to a warning --- CHANGELOG.md | 5 +++++ python/private/patch_whl.bzl | 19 +++++++++++++++++++ python/private/repack_whl.py | 11 +++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 405755433a..2077ebbbcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,11 @@ A brief description of the categories of changes: * (bzlmod pip.parse) Requirements files with duplicate entries for the same package (e.g. one for the package, one for an extra) now work. * (whl_library) Actually use the provided patches to patch the whl_library. + On Windows the patching may result in files with CRLF line endings, as a result + the RECORD file consistency requirement is lifted and now a warning is emitted + instead with a location to the patch that could be used to silence the warning. + Copy the patch to your workspace and add it to the list if patches for the wheel + file if you decide to do so. [0.XX.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.XX.0 diff --git a/python/private/patch_whl.bzl b/python/private/patch_whl.bzl index 24b8a0b565..9e3119f744 100644 --- a/python/private/patch_whl.bzl +++ b/python/private/patch_whl.bzl @@ -73,11 +73,15 @@ def patch_whl(rctx, *, python_interpreter, whl_path, patches, **kwargs): parsed_whl.platform_tag, ])) + record_patch = rctx.path("RECORD.patch") + result = rctx.execute( [ python_interpreter, "-m", "python.private.repack_whl", + "--record-patch", + record_patch, whl_input, whl_patched, ], @@ -97,4 +101,19 @@ def patch_whl(rctx, *, python_interpreter, whl_path, patches, **kwargs): ), ) + if record_patch.exists: + record_patch_contents = rctx.read(record_patch) + warning_msg = """WARNING: the resultant RECORD file of the patch wheel is different + + If you are patching on Windows, you may see this warning because of + a known issue (bazelbuild/rules_python#1639) with file endings. + + If you would like to silence the warning, you can apply the patch that is stored in + {record_patch}. The contents of the file are below: +{record_patch_contents}""".format( + record_patch = record_patch, + record_patch_contents = record_patch_contents, + ) + print(warning_msg) # buildifier: disable=print + return rctx.path(whl_patched) diff --git a/python/private/repack_whl.py b/python/private/repack_whl.py index 074e30db74..be113ef791 100644 --- a/python/private/repack_whl.py +++ b/python/private/repack_whl.py @@ -113,6 +113,11 @@ def main(sys_argv): type=pathlib.Path, help="The original wheel file that we have patched.", ) + parser.add_argument( + "--record-patch", + type=pathlib.Path, + help="The output path that we are going to write the RECORD file patch to.", + ) parser.add_argument( "output", type=pathlib.Path, @@ -163,8 +168,10 @@ def main(sys_argv): got_record, out.distinfo_path("RECORD"), ) - logging.exception(f"Please also patch the RECORD file with:\n{record_diff}") - return 1 + args.record_patch.write_text(record_diff) + logging.warning( + f"Please apply patch to the RECORD file ({args.record_patch}):\n{record_diff}" + ) if __name__ == "__main__":