From a3254e0642028530c23998fcfba5a56467884a8d Mon Sep 17 00:00:00 2001 From: Dimitar Kovachev Date: Sat, 23 Nov 2024 22:01:52 +0200 Subject: [PATCH 1/3] Fix creating ZIP archives with no file extension --- src/python/pants/core/util_rules/archive.py | 5 ++++- src/python/pants/core/util_rules/archive_test.py | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/python/pants/core/util_rules/archive.py b/src/python/pants/core/util_rules/archive.py index 781d004a3f9..ae69eed70af 100644 --- a/src/python/pants/core/util_rules/archive.py +++ b/src/python/pants/core/util_rules/archive.py @@ -69,9 +69,12 @@ async def create_archive( argv: tuple[str, ...] = ( bash_binary.path, "-c", + # Note: The -A (--adjust-sfx) option causes zip to treat the given archive name as-is. + # This works even when archive isn't created as a self-extracting archive + # see https://unix.stackexchange.com/a/557812 softwrap( f""" - {zip_binary.path} --names-stdin {shlex.quote(request.output_filename)} + {zip_binary.path} --adjust-sfx --names-stdin {shlex.quote(request.output_filename)} < {FILE_LIST_FILENAME} """ ), diff --git a/src/python/pants/core/util_rules/archive_test.py b/src/python/pants/core/util_rules/archive_test.py index 990c93ba360..fc0aa123222 100644 --- a/src/python/pants/core/util_rules/archive_test.py +++ b/src/python/pants/core/util_rules/archive_test.py @@ -120,8 +120,8 @@ def test_extract_non_archive(rule_runner: RuleRunner) -> None: assert DigestContents([FileContent("test.sh", b"# A shell script")]) == digest_contents -def test_create_zip_archive(rule_runner: RuleRunner) -> None: - output_filename = "demo/a.zip" +@pytest.mark.parametrize("output_filename", ["demo/a.zip", "demo/a.whl", "demo/a"]) +def test_create_zip_archive(rule_runner: RuleRunner, output_filename: str) -> None: input_snapshot = rule_runner.make_snapshot(FILES) created_digest = rule_runner.request( Digest, @@ -136,7 +136,9 @@ def test_create_zip_archive(rule_runner: RuleRunner) -> None: assert set(zf.namelist()) == set(FILES.keys()) # We also use Pants to extract the created archive, which checks for idempotency. - extracted_archive = rule_runner.request(ExtractedArchive, [created_digest]) + extracted_archive = rule_runner.request( + ExtractedArchive, [MaybeExtractArchiveRequest(digest=created_digest, use_suffix=".zip")] + ) digest_contents = rule_runner.request(DigestContents, [extracted_archive.digest]) assert digest_contents == EXPECTED_DIGEST_CONTENTS From 50a3a4be334a70f3bfc993e9d512cde032ca7071 Mon Sep 17 00:00:00 2001 From: Dimitar Kovachev Date: Sat, 23 Nov 2024 22:02:08 +0200 Subject: [PATCH 2/3] Remove unused ZipBinary method --- src/python/pants/core/util_rules/system_binaries.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/python/pants/core/util_rules/system_binaries.py b/src/python/pants/core/util_rules/system_binaries.py index bb9e332ce0a..4b3f04bfe9b 100644 --- a/src/python/pants/core/util_rules/system_binaries.py +++ b/src/python/pants/core/util_rules/system_binaries.py @@ -294,10 +294,7 @@ class ArchiveFormat(Enum): class ZipBinary(BinaryPath): - def create_archive_argv( - self, output_filename: str, input_files: Sequence[str] - ) -> tuple[str, ...]: - return (self.path, output_filename, *input_files) + pass class UnzipBinary(BinaryPath): From a49038dab32536f5ab7b89a3774a6ec2c468106c Mon Sep 17 00:00:00 2001 From: Dimitar Kovachev Date: Thu, 28 Nov 2024 07:35:35 +0200 Subject: [PATCH 3/3] Add an entry to the release notes --- docs/notes/2.25.x.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/notes/2.25.x.md b/docs/notes/2.25.x.md index caa7730be45..a4825547bcc 100644 --- a/docs/notes/2.25.x.md +++ b/docs/notes/2.25.x.md @@ -18,6 +18,7 @@ established for this purpose. This non-profit's only source of revenue is ### General - [Fixed](https://github.com/pantsbuild/pants/pull/21665) bug where `pants --export-resolve= --export-py-generated-sources-in-resolve=` fails (see [#21659](https://github.com/pantsbuild/pants/issues/21659) for more info). +- [Fixed](https://github.com/pantsbuild/pants/pull/21694) bug where an `archive` target is unable to produce a ZIP file with no extension (see [#21693](https://github.com/pantsbuild/pants/issues/21693) for more info). ### New Options System