moreorless: Python Diff Wrapper

0.5.0 · active · verified Fri Apr 10

Moreorless is a thin Python wrapper around `difflib.unified_diff` designed to simplify its usage and address common edge cases, such as the "No newline at eof" issue. It provides a more user-friendly interface for generating unified diffs, applying patches, and producing colorized diff output. The current version is 0.5.0, with an irregular release cadence based on contributions and feature enhancements.

Warnings

Install

Imports

Quickstart

This example demonstrates how to generate a raw unified diff string using `unified_diff` and how to print a colorized diff to the console using `echo_color_unified_diff`. The `filename` arguments are used in the diff header.

from moreorless import unified_diff
from moreorless.click import echo_color_unified_diff

old_text = """Line 1\nLine 2\nLine 3 - original\nLine 4\n"""
new_text = """Line 1\nLine 2 - modified\nLine 3 - changed\nLine 5 - new\n"""

# Get a raw unified diff string
diff_string = unified_diff(old_text, new_text, 'old_file.txt', 'new_file.txt')
print("\n--- Raw Unified Diff ---")
print(diff_string)

# Or print a colorized diff directly to stdout (requires 'click' package)
print("\n--- Colorized Diff (using click) ---")
echo_color_unified_diff(old_text, new_text, 'old_file.txt', 'new_file.txt')

view raw JSON →