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.32-cp313-cp313-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 235.7 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0rc3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49f667b609aceb7e34dac0c8e9f6a6f28bc84eab10f0f3d033aa4c331cc05196 |
|
MD5 | 4b4c21170de175f907fe7e787145b7fe |
|
BLAKE2b-256 | b41d023660fd2e8dc889cf4af3211c13f15b69f45b3c5136de49bae1cc98c2a3 |
File details
Details for the file ocdiff-0.0.32-cp313-cp313-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp313-cp313-macosx_10_13_x86_64.whl
- Upload date:
- Size: 243.3 kB
- Tags: CPython 3.13, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0rc3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38c475bf994a46a267a7c3928d3e96e9777cde7c2590f92f9c7430a181feff17 |
|
MD5 | 8cc75ab75c852bed4bfa5bbaf3a8e26b |
|
BLAKE2b-256 | 758ef774d7ae099243d40dbd617814ac9faafaad90aa27b1efb31ced0d5cf582 |
File details
Details for the file ocdiff-0.0.32-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 305.6 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 | ffac20287f4fd69e4214f3e23a073a13658e34b6d5a8e69c564aee94158569fc |
|
MD5 | 5c9c608b4faedc20205f48e3ce1981d7 |
|
BLAKE2b-256 | bb9b5d8695ca2ecab288f43094422dea7b933850c221715051a095fbe9304871 |
File details
Details for the file ocdiff-0.0.32-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 307.7 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 | 01df5d8bd57ca442de3184b96e8c1099b8b19e4255f210638bc73a456ec8bb6c |
|
MD5 | 119bf7b35993d6bb3f397bde42bf2be2 |
|
BLAKE2b-256 | 4e54bc09c2f5336d02176603ae3f5cba0d70d76a50ce5e369aed9cbcf2e3b4f5 |
File details
Details for the file ocdiff-0.0.32-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 326.5 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 | 9756025afcc46c984df1db855f0456b9f356d81d05c941d0c0de49f6f8e77757 |
|
MD5 | 98107f1310fe15c570c4ac675df1b917 |
|
BLAKE2b-256 | e46dba43f8003a0db1fd75de2bb124d27ae0be6b3acf933b1c2b4c4d30489180 |
File details
Details for the file ocdiff-0.0.32-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 235.7 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 707b67244b772f662c8703de7528a9ecc8f0ef7d3779da6b4147d196745fe0c0 |
|
MD5 | dce148a1a20358ddfda2f6ca201c0309 |
|
BLAKE2b-256 | 022fc7894e33cc4d01d0eb534711c351bb38c7ebb8fa0a8893c6896dbad03e9c |
File details
Details for the file ocdiff-0.0.32-cp312-cp312-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp312-cp312-macosx_10_13_x86_64.whl
- Upload date:
- Size: 243.3 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 | e54c406471c2868566a72b615dfd43dc05352e570dab8a48273d2b5d591734f6 |
|
MD5 | d399939fe42cd571dafe67e67ac9ec1c |
|
BLAKE2b-256 | 40f19976ae63094a95eb31d1935dc81017ffbdfb3cb2860273b506eaabb75c22 |
File details
Details for the file ocdiff-0.0.32-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 305.9 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ed2c1a7bb2bde62a0b77c8d79079b44500c8a5121b70905cac1685554ddc3e5 |
|
MD5 | c1707f91cd11468ce8b2dce1e8643e75 |
|
BLAKE2b-256 | db77df69b5703b15f5da11bc8133cbf5dc4c85c50bc0b78c96d58536e8aaacb7 |
File details
Details for the file ocdiff-0.0.32-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 307.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ed1423235c8369372a7f9bb42b8d3ae319364936bd11fe53495d8d1164c9445 |
|
MD5 | 4ad947ac43fc05465e96b8bab07d3069 |
|
BLAKE2b-256 | 3d9c02f8d50d234c07a6781bbf38eee5d551892edbba5417fbe3fd654bd0b30d |
File details
Details for the file ocdiff-0.0.32-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 326.9 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dec6949a3437de9d68c182b2eea05d8b2472b9fb4f738e769bf72d6c3ec860df |
|
MD5 | 6d66f22e127a298d90077209b922592e |
|
BLAKE2b-256 | ce91a6634c6d1ff0908ae7aa229a070f45819344d263c70210a2c86bb22c70f9 |
File details
Details for the file ocdiff-0.0.32-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 235.6 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 | 81caaa6ef7abc17eed664c243a915e09550e7e20b0d53dc8bd086e62408c7b16 |
|
MD5 | 7b48a96109b6788d4e26b6b0d8fb2647 |
|
BLAKE2b-256 | e125164c9fb9d9fa6136f43fcab4e01e6790fd6994ff9d70197cfa8b8757387c |
File details
Details for the file ocdiff-0.0.32-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ocdiff-0.0.32-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 243.4 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 | 9e57c7c992be2e7cc78e1beac96b02f0edac1a2fc1827a6793f530b0420d21e4 |
|
MD5 | 3e850e68ae4e42371a66a43e08fd90d2 |
|
BLAKE2b-256 | 23ccf35eb737eb22cfb8bdc23be35655b030a8792d78f801faa628076206b400 |