Skip to content

Compress snapshot file#4

Merged
ofekby merged 11 commits intomainfrom
compress-snapshot
Dec 2, 2025
Merged

Compress snapshot file#4
ofekby merged 11 commits intomainfrom
compress-snapshot

Conversation

@ofekby
Copy link
Collaborator

@ofekby ofekby commented Dec 2, 2025

This pull request updates the snapshot file format in Snaplint from plain JSON to gzip-compressed JSON (.json.gz). The change affects the CLI, core snapshot logic, documentation, and tests to ensure all snapshot files are handled as compressed files for improved efficiency and compatibility.

Snapshot file format migration:

  • All references to snapshot files in the codebase, documentation, and tests are updated from .json to .json.gz to indicate gzip compression. This includes default paths, help text, and file handling logic. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

Snapshot read/write logic:

  • Snapshot writing and reading functions in src/snaplint/snapshot.py now use gzip compression and decompression, respectively. File I/O is switched to binary mode, and error handling for gzip files is added. [1] [2] [3] [4]

Documentation updates:

  • The README.md is updated to clarify that snapshots are now stored as gzip-compressed JSON files, with all examples and explanations reflecting the new .json.gz extension. [1] [2] [3]

Test suite updates:

  • All relevant tests are updated to use gzip when reading and writing snapshot files, and to expect the .json.gz extension. This ensures tests validate the new compressed format. [1] [2] [3] [4] [5] [6]

Version bump:

  • The project version is incremented from 0.5.0 to 0.6.0 in pyproject.toml to reflect this breaking change.

Copilot AI review requested due to automatic review settings December 2, 2025 10:25
@ofekby ofekby merged commit ce6f32c into main Dec 2, 2025
8 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the snapshot file format from plain JSON (.json) to gzip-compressed JSON (.json.gz) to improve storage efficiency. This is a breaking change appropriately reflected by bumping the version from 0.5.0 to 0.6.0.

Key changes:

  • Updated snapshot read/write functions to use gzip compression and binary file I/O
  • Modified all file paths, help text, and documentation to use .json.gz extension
  • Updated test suite to handle gzip-compressed snapshots

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/snaplint/snapshot.py Added gzip compression to write_snapshot() and decompression to read_snapshot(), changed I/O to binary mode, added gzip.BadGzipFile error handling
src/snaplint/cli.py Updated default snapshot paths to use .json.gz, changed file open modes to binary ('wb'/'rb'), updated help text
tests/test_cli.py Added gzip import, updated snapshot file fixture path, modified snapshot validation to use gzip.open()
tests/test_e2e.py Added gzip import, updated all snapshot file paths to .json.gz, modified snapshot reading to use gzip.open()
README.md Updated documentation to reflect gzip-compressed format and .json.gz extension
pyproject.toml Bumped version from 0.5.0 to 0.6.0
uv.lock Updated version reference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

data = json.loads(json_str)
return SnapshotFile.model_validate(data)
except gzip.BadGzipFile as e:
raise SnapshotReadError(f"Invalid gzip file: {e}") from e
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling should also catch UnicodeDecodeError separately to provide a clearer error message when the gzip file decompresses successfully but contains invalid UTF-8 data. Currently, it would be caught by the generic Exception handler which gives a less specific error message. Consider adding:

except UnicodeDecodeError as e:
    raise SnapshotReadError(f"Invalid UTF-8 encoding in snapshot file: {e}") from e

between the gzip.BadGzipFile and json.JSONDecodeError handlers.

Suggested change
raise SnapshotReadError(f"Invalid gzip file: {e}") from e
raise SnapshotReadError(f"Invalid gzip file: {e}") from e
except UnicodeDecodeError as e:
raise SnapshotReadError(f"Invalid UTF-8 encoding in snapshot file: {e}") from e

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants