Skip to content

Commit 9c3d99f

Browse files
Freed-Wujayqi
andauthored
Fix #21, don't change output name (#22)
* Fix #21, don't change output name * Add test for suffix behavior * Fix reinstallation of packages for tests * Test printing * Clearer condition * Bump version and add changelog * Formatting --------- Co-authored-by: Jay Qi <[email protected]>
1 parent e00f981 commit 9c3d99f

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

cli/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog — rpzip
22

3+
## v0.1.2 (2025-07-26)
4+
5+
- Fixed inconsistency with `zip` with output file suffixes. `rpzip` now only adds a `.zip` suffix if the output file does not have a suffix already. Previously, an existing suffix would be replaced by `.zip`. ([Issue #21](https://github.com/drivendataorg/repro-zipfile/issues/21), [PR #22](https://github.com/drivendataorg/repro-zipfile/pull/22) contributed by [@Freed-Wu](https://github.com/Freed-Wu))
6+
37
## v0.1.1 (2024-02-02)
48

59
- Fixed misformatted `--version` output.

cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "rpzip"
7-
version = "0.1.2.dev"
7+
version = "0.1.2"
88
description = "A lightweight command-line program for creating reproducible/deterministic ZIP archives."
99
readme = "README.md"
1010
requires-python = ">=3.8"

cli/rpzip.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ def rpzip(
9393
logger.debug("recurse_paths: %s", recurse_paths)
9494

9595
# Set output archive path
96-
if not out_file.endswith(".zip"):
97-
out_path = Path(out_file).with_suffix(".zip").resolve()
98-
else:
99-
out_path = Path(out_file).resolve()
96+
out_path = Path(out_file)
97+
if not out_path.suffix:
98+
out_path = out_path.with_suffix(".zip")
99+
out_path = out_path.resolve()
100100
logger.debug("writing to: %s", out_path)
101101

102102
# Process inputs

justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typecheck:
2929
# Run tests
3030
test *args:
3131
uv run --python {{python}} --no-editable --all-extras --no-dev --group test --isolated \
32+
--reinstall-package rpzip --reinstall-package repro-zipfile \
3233
python -I -m pytest {{args}}
3334

3435
# Run all tests with Python version matrix

tests/test_cli.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,48 @@ def test_zip_multiple_recursive(base_path):
8484
assert_archive_contents_equals(rpzip_out, zip_out)
8585

8686

87-
def test_zip_no_suffix(base_path):
87+
def test_zip_no_suffix_adds_suffix(base_path):
88+
"""Appropriately add .zip suffix if file does not have one."""
8889
data_file = file_factory(base_path)
8990

90-
rpzip_out = base_path / "rpzip.zip"
91-
rpzip_args = [str(rpzip_out.with_suffix("")), str(data_file)]
91+
# Should add .zip to argument without suffix
92+
rpzip_out_expected = base_path / "rpzip.zip"
93+
rpzip_out_arg = rpzip_out_expected.with_suffix("")
94+
rpzip_args = [str(rpzip_out_arg), str(data_file)]
9295
rpzip_result = runner.invoke(app, rpzip_args)
9396
assert rpzip_result.exit_code == 0, rpzip_args
97+
assert rpzip_out_expected.exists(), (rpzip_args, list(base_path.iterdir()))
9498

95-
zip_out = base_path / "zip.zip"
96-
zip_cmd = ["zip", str(zip_out.with_suffix("")), str(data_file)]
99+
# zip also adds .zip to argument another argument without suffix
100+
zip_out_expected = base_path / "zip.zip"
101+
zip_out_arg = zip_out_expected.with_suffix("")
102+
zip_cmd = ["zip", str(zip_out_arg), str(data_file)]
97103
zip_result = subprocess.run(zip_cmd)
98104
assert zip_result.returncode == 0, zip_cmd
105+
assert zip_out_expected.exists(), (zip_cmd, list(base_path.iterdir()))
99106

100-
assert_archive_contents_equals(rpzip_out, zip_out)
107+
assert_archive_contents_equals(rpzip_out_expected, zip_out_expected)
108+
109+
110+
def test_zip_existing_suffix_does_not_add_suffix(base_path):
111+
"""Does not add .zip suffix if file already has one."""
112+
data_file = file_factory(base_path)
113+
114+
# Should not add .zip to argument with existing suffix
115+
rpzip_out_expected = base_path / "rpzip.some_suffix"
116+
rpzip_args = [str(rpzip_out_expected), str(data_file)]
117+
rpzip_result = runner.invoke(app, rpzip_args)
118+
assert rpzip_result.exit_code == 0, rpzip_args
119+
assert rpzip_out_expected.exists(), (rpzip_args, list(base_path.iterdir()))
120+
121+
# zip also does not add .zip to argument with existing suffix
122+
zip_out_expected = base_path / "zip.some_suffix"
123+
zip_cmd = ["zip", str(zip_out_expected), str(data_file)]
124+
zip_result = subprocess.run(zip_cmd)
125+
assert zip_result.returncode == 0, zip_cmd
126+
assert zip_out_expected.exists(), (zip_cmd, list(base_path.iterdir()))
127+
128+
assert_archive_contents_equals(rpzip_out_expected, zip_out_expected)
101129

102130

103131
def test_verbosity(rel_path):

0 commit comments

Comments
 (0)