Skip to main content

Remove noise from notebooks for cleaner version control diffs

Project description

Squeaky

✨ Make your Jupyter notebooks squeaky clean ✨

Squeaky removes unwanted changes to your notebooks to make your Git diffs cleaner. Tools like nbdime and ReviewNB are awesome, but can be clunky and difficult to learn. Instead, Squeaky makes it easier to manage notebook diffs with standard Git tools.

Usage

First, install:

pip install squeaky

Then use Squeaky to clean a notebook:

squeaky path/to/notebook(s).ipynb

To check notebooks without modifying them, use the --check flag.

squeaky path/to/notebook.ipynb --check

Jupyter pre-save hook

You can automatically run your notebooks through Squeaky before saving them by editing your Jupyter config file. First, find the location of your config directory by running

jupyter --config-dir

Your config directory may contain either a jupyter_lab_config.py or a jupyter_server_config.py (if neither exists, create an empty file with either of these names).

:warning: If you're using Jupyter notebook < 7, then the file will be called jupyter_notebook_config.py.

Then, add the following lines to that config file.

from squeaky import squeaky_clean_hook
c.FileContentsManager.pre_save_hook = squeaky_clean_hook

Pre-commit hook

To use with pre-commit, add the following to your .pre-commit-config.yaml.

repos:
  - repo: local
    hooks:
      - name: Clean notebooks
        id: clean-notebooks
        entry: squeaky --check
        language: python
        files: '(.*?).ipynb$'

Features

  • Reset metadata

    If you're running your notebooks in CI, then you probably don't care about the last environment a notebook was edited in. Squeaky resets notebook metadata to a standard metadata.

  • Minify SVGs

    Setting code image outputs to SVGs makes images look great, but comes with horrendous diffs. Squeaky minifies SVG outputs to a single line, which also reduces file size.

  • Reset IDs in SVG outputs

    SVG outputs have another problem: Randomized IDs in the source. Squeaky re-generates these IDs deterministically using on the cell's unique ID. This means re-running the notebook won't change the output unless the image actually changes.

  • Remove trailing whitespace

    Often missed in markdown (but not in version control), Squeaky removes trailing whitespace from ends of lines and empty lines from ends and beginnings of cells.

  • Remove empty cells

    Squeaky removes empty cells, including that annoying empty code cell at the bottom of every other notebook.

  • Add missing cell IDs

    Cells without IDs now raise a warning in nbformat. Squeaky adds these IDs for you so you don't need to think about it.

Contributing

To install requirements and add pre-commit hooks:

pip install -r requirements-dev.txt
pre-commit install

To run unit tests (also run on commit):

tox

Wishlist

  • Turn off features through config file

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

squeaky-0.7.1.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

squeaky-0.7.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file squeaky-0.7.1.tar.gz.

File metadata

  • Download URL: squeaky-0.7.1.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for squeaky-0.7.1.tar.gz
Algorithm Hash digest
SHA256 790b1ab4af4dcacae3149a0bf4352b25d463d9be88bd70632b84fce2f563a7e9
MD5 443dde8c688f35ce442c4dd08955670c
BLAKE2b-256 ac2e963533f39fc2be649563ae8df16f17ccda84394f969ceadbec4ce66890bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for squeaky-0.7.1.tar.gz:

Publisher: release.yml on frankharkins/squeaky

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file squeaky-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: squeaky-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for squeaky-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 917e8372a8c210b24c3dcf06c482410a0d0feb04e46643ac1cb729dde1453a55
MD5 866dd0d5c0464d0ad5e1c2273789b676
BLAKE2b-256 259d2e8d27c5c012fcddef8ac4d0b79c7f791a602bab637f9a3530c65bacf865

See more details on using hashes here.

Provenance

The following attestation bundles were made for squeaky-0.7.1-py3-none-any.whl:

Publisher: release.yml on frankharkins/squeaky

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page