Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Creating ZIP archives with no file extension #21694

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/notes/2.25.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<resolve> --export-py-generated-sources-in-resolve=<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

Expand Down
5 changes: 4 additions & 1 deletion src/python/pants/core/util_rules/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"""
),
Expand Down
8 changes: 5 additions & 3 deletions src/python/pants/core/util_rules/archive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
5 changes: 1 addition & 4 deletions src/python/pants/core/util_rules/system_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading