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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file delta_reduce-0.1.1.tar.gz.
File metadata
- Download URL: delta_reduce-0.1.1.tar.gz
- Upload date:
- Size: 6.0 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2f83a31eed310555d90d773ae360c220d211060c1186686d72ba33d2363c370
|
|
| MD5 |
1c1d07d01e4512158648165bde97cfbe
|
|
| BLAKE2b-256 |
3a72c0424facec0a6036a9f2ef65a1f464c5e4119a7587b28d7d2e921affac81
|
File details
Details for the file delta_reduce-0.1.1-py3-none-any.whl.
File metadata
- Download URL: delta_reduce-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.7 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c06c13c8e417343d21c871b7ee0188a549d0a12808dde2930b1c0e752060b07b
|
|
| MD5 |
d7e861a8bf15afeca88967e820b353d7
|
|
| BLAKE2b-256 |
be3257ffaa6fa13ecdb3aba1efa593599c1b79434c93dce551f2dea20f9c9227
|