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
.
git tag -a v0.0.x head -m v0.0.x
git push origin v0.0.x
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
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
Close
Hashes for ocdiff-0.0.28-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b01d5ae84dd8c9bcc6e4ed747c3d0971fee11c449b71095e1149a980adef618 |
|
MD5 | fb7573e850fb4995331c6953f755a618 |
|
BLAKE2b-256 | 590168236ffd158b7438b629a7ab673d37ac54f31ce656709516a75837cc2343 |
Close
Hashes for ocdiff-0.0.28-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2b2c7f5bd18c09afddb0573e265bcd23302311245f66f51d755734a94ce59a0 |
|
MD5 | 0a8603126e01f194d929bc85e66e60ec |
|
BLAKE2b-256 | f6b17376aaefc0bfa17b05ad60069d6d969741476a58e3af036dcab59c1616c9 |
Close
Hashes for ocdiff-0.0.28-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29be5d4da52a7ac13f6d23949342b1a2caf23ab336097a3443626a91d45185aa |
|
MD5 | f6cc831e6ca2715b7797237b4cadb0cf |
|
BLAKE2b-256 | af1f526769a0512537f6330c8f19976673d82cee1ced90c31529e8e64fdcb87d |
Close
Hashes for ocdiff-0.0.28-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84d9f5adb7d68683eede71574ffda14bbb2192ad9d644d36b9d51e336e33883c |
|
MD5 | 7a0a1aaacc0ec1e9d98ea0b53d545919 |
|
BLAKE2b-256 | 98f64871dd756397b7c89c24fcc5b747b5859718f737bcdd35f4e43b1c868b63 |
Close
Hashes for ocdiff-0.0.28-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69b31402bd0c9c0db305fca7c118afc2561b5537fae4c8fbd2e0bbc19be2dfcc |
|
MD5 | 85fbd7ba456bd688806838bf566ce9ef |
|
BLAKE2b-256 | ac701dc21745e0150d1a5ed0f880d692654cb8015da1692a9fd28602dfa122f5 |
Close
Hashes for ocdiff-0.0.28-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd0a5b8bc57020a5ffaf10da47317582325ca8adf5daf8fa94b8b8583e471716 |
|
MD5 | 0d881a849432504dec6c03fef56c64a0 |
|
BLAKE2b-256 | 31a682d2d250dc3759cfdae0722d5f41f458f6ff0a6215e1e74b0cfc8d90d5e1 |
Close
Hashes for ocdiff-0.0.28-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8e412cd3b6f88e2692a04052fae1198f77b0839ca517b860023aeaef4080659 |
|
MD5 | c216ad9c6d1040c16b96c96fdd47d026 |
|
BLAKE2b-256 | c7517bbe2b4ba162c877b6e5db10aa952ddd4370957a5c2b2d3524c47d31e182 |
Close
Hashes for ocdiff-0.0.28-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab67187bcbc7085e1b58d95b3905aaf617bea08e3c4d52a9c3f437169799c42a |
|
MD5 | 2b00aa9f85bda197cbe718c6baaa79e8 |
|
BLAKE2b-256 | 0016a17cb22842b9b92622574c54c055d9bde060fa042ae7f8492ad0652540d4 |
Close
Hashes for ocdiff-0.0.28-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d5b5431d582ed89cdcd6258547d93fcecbddd5a4e896d8e51f406f036ff048b |
|
MD5 | a0da3951e7a0c3ad326e15da8799a561 |
|
BLAKE2b-256 | 119eedc75c42ba0036dccbf0e70609c3d95cca5910a802c478412c223d896cd5 |
Close
Hashes for ocdiff-0.0.28-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d6c09706bfed02ab5d7726e21cdede9aecc96092af831c868c354ddd603947f |
|
MD5 | 4db54e91c191e650fc3a24bb00f081fb |
|
BLAKE2b-256 | 8f350dfd1e88c5bb1e5471b3f2e989b4cf3f416bcd37bf7989489fd060b7991a |