difftastic Python wrapper
Project description
ocdiff
Fast and simple side-by-side diff library for Python - wraps similar, inspired by icdiff.
Usage
pip install ocdiff
ocdiff.html_diff(
a: str,
b: str,
context_lines: int | None = None,
max_total_width: int | None = None,
) -> str
ocdiff.console_diff(
a: str,
b: str,
context_lines: int | None = None,
max_total_width: int | None = None,
) -> str
Example Output
CLI usage
ocdiff a.txt b.txt
Usage in pytest
with rich
In your conftest.py
, add:
import ocdiff
import ocdiff.helpers
import rich.console
def rich_repr(o: Any) -> str:
string_io = io.StringIO()
rich.console.Console(
file=string_io,
width=ocdiff.helpers.terminal_width() // 2 - 10,
tab_size=4,
no_color=True,
highlight=False,
log_time=False,
log_path=False,
).print(o)
string_io.seek(0)
return string_io.getvalue()
def pytest_assertrepr_compare(config: Any, op: str, left: Any, right: Any) -> list[str] | None:
very_verbose = config.option.verbose >= 2
if not very_verbose:
return None
if op != "==":
return None
try:
if abs(left + right) < 100:
return None
except TypeError:
pass
try:
if isinstance(left, str) and isinstance(right, str):
pretty_left = left
pretty_right = right
else:
pretty_left = rich_repr(left)
pretty_right = rich_repr(right)
return ocdiff.console_diff(
pretty_left,
pretty_right,
context_lines=10,
max_total_width=ocdiff.helpers.terminal_width() - len("E "),
).splitlines()
except Exception:
return None
Install/Develop
uv pip install -e '.[dev]'
maturin develop
Make release
- Add pypi token and user =
__token__
to settings (do this once). - Upversion
pyproject.toml
.
export VERSION=$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])'); git tag -a v$VERSION head -m v$VERSION && git push origin v$VERSION
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 Distributions
Built Distributions
File details
Details for the file ocdiff-0.0.30-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ocdiff-0.0.30-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 314.7 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b824e7c825906e6c47f6bf8a8cd893b6b4140e6366d96448656908faece07f9 |
|
MD5 | d3676892735e4833f55f26d43648043d |
|
BLAKE2b-256 | bb03e08c7a6581d1db955a37607cf9121d7d220a802ce90e84a788220c9fefed |
File details
Details for the file ocdiff-0.0.30-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: ocdiff-0.0.30-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 316.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e07dd93dbf127bd8497f37bdc63cc8fb03e8f9709088e1c4c5e93654efbe4ab4 |
|
MD5 | f0079c1aea82cc18fb17c9b464a17bda |
|
BLAKE2b-256 | f7f599e4a03b13cf19cac8ec40e78d97082b7d880136b7392c65a678ad9fd596 |
File details
Details for the file ocdiff-0.0.30-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: ocdiff-0.0.30-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 333.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23a7c015a1a2b54ffd0f84fa4888ba563a75b01d2891ed9903acac248f56284f |
|
MD5 | a0b0363b7f45da8f492ff4ec78b20a12 |
|
BLAKE2b-256 | c51f728cd2905e91fbdd715594f60c5703e47f30534406da71437ef62a5b31e8 |
File details
Details for the file ocdiff-0.0.30-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ocdiff-0.0.30-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 238.1 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04f5991ad2aa316af4394e081977dc98fb1037db1ba12a7356b439be36faa00d |
|
MD5 | d7e29d9375de92b03f104ebf3fc9ff04 |
|
BLAKE2b-256 | a80ff27d7592aa871cb1037a1fb82a3271d83a648d1cb9596861d473ecba58db |
File details
Details for the file ocdiff-0.0.30-cp312-cp312-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: ocdiff-0.0.30-cp312-cp312-macosx_10_13_x86_64.whl
- Upload date:
- Size: 246.9 kB
- Tags: CPython 3.12, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f483e13bf5e893214a2878f2a2076a82cc79217a6f8f5b8024d42825dd6aed71 |
|
MD5 | 889692102fe7f9d610d20e0814448d84 |
|
BLAKE2b-256 | b4c7124b934d21d29c18159b88dc0d791acd6f03f28950667d979cb041dd39cf |
File details
Details for the file ocdiff-0.0.30-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ocdiff-0.0.30-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 238.3 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f0529f937c7430a15be548d38d0bbd9a7f56fe5b8bd561778dd26b8aeb60a02 |
|
MD5 | 45742a8fa0a28559fc03c4fb9e380df3 |
|
BLAKE2b-256 | 2bb89fa18a639c4bf804c92b7bb672db05769c79b141ef27fa1a63d365488017 |
File details
Details for the file ocdiff-0.0.30-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ocdiff-0.0.30-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 246.9 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92ecb58e66d76da96732502aece2ed0618a1594ef98843bb4a089238d79a3e97 |
|
MD5 | e574f80a50ab4b6b26e1be3b85845dac |
|
BLAKE2b-256 | edd5b43ad7a8d29bd8c21a25906822c3894ac808ac2c78485beb673cd3d6949a |