Skip to main content

A delta-reduction CLI tool for minimising files

Project description

delta-reduce

A delta-reduction tool for minimising a file to the smallest version that still satisfies a given test. Similar in spirit to CReduce, but simpler: it only deletes lines, not arbitrary sub-expressions or tokens.

How it works

The tool repeatedly tries to delete chunks of lines from the input file. It scans from the bottom of the file upward, testing each deletion. The chunk size starts at the full file size and is reduced as the algorithm makes passes over the file. After 4 successful deletions the chunk size grows again, speeding up reduction when progress is easy. This repeats until a full pass removes nothing.

Multiple passes alternate an offset of 0 and 1 to avoid missing deletions that straddle chunk boundaries.

Installation

pip install delta-reduce

Usage

delta-reduce --test <script> --input <file> [-n <threads>]
Option Description
--test SCRIPT Script that exits 0 if the candidate file is acceptable, non-zero otherwise.
--input FILE File to reduce. Overwritten in place as progress is made.
-n N Number of parallel threads (default: 4).
-v, --verbose Print each tested deletion with its line range, chunk size, duration, and result.

The original file is backed up to <file>.orig on the first run. Subsequent runs will not overwrite it.

Test script interface

The script is invoked with its working directory set to a temporary directory containing the candidate file under the original filename. Any external resources must be referenced by absolute path.

#!/bin/sh
# Example: keep reducing as long as the file still triggers a compiler error
gcc -c input.c 2>&1 | grep -q 'use of undeclared identifier'

Development

uv venv && uv pip install -e .
pytest

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

delta_reduce-0.1.2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

delta_reduce-0.1.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file delta_reduce-0.1.2.tar.gz.

File metadata

  • Download URL: delta_reduce-0.1.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for delta_reduce-0.1.2.tar.gz
Algorithm Hash digest
SHA256 174639b49084236e4f005f18e253ee1c9e94f5756f98bc696b77a9dfc4609fef
MD5 b43100b67dea9effe6801f9a877e1d6c
BLAKE2b-256 79ffdd35290110d756debe5e21235ebefa16a3ac29b7d52c678b816f69f7deeb

See more details on using hashes here.

File details

Details for the file delta_reduce-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: delta_reduce-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for delta_reduce-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 50cad6bddbeaacf301e12b597ab5a45e1763e589a61873c3440553bc59fe57a5
MD5 37f2d6e62945b3a77145e769443d5908
BLAKE2b-256 f8576305b03efb3348048e629ac8eeab2e6184a7fa5386f667f37f60927dc54a

See more details on using hashes here.

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