A tool to get diffs between text strings
Project description
diff-getter
テキスト文字列間の差分を取得するシンプルなPythonユーティリティです。異なる形式(unified形式とcontext形式)での差分出力をサポートしています。
特徴
- 2つのテキスト文字列間の差分を簡単に取得
- unified形式とcontext形式の両方をサポート
- リスト形式または文字列形式での差分出力
- Pythonライブラリとしての使用、またはコマンドラインツールとしての使用が可能
インストール
pipを使用してインストールできます:
pip install diff-getter
使用方法
Pythonライブラリとして
Unified形式の差分を取得
from diff_getter import get_unified_diff, get_unified_diff_string
# テキストの準備
text1 = "これはテストです。\n1行目\n2行目\n3行目"
text2 = "これはテストです。\n1行目\n2行目(変更)\n4行目"
# リスト形式で差分を取得
diff_list = get_unified_diff(text1, text2)
print(diff_list)
# 出力:
# ['--- 変更前', '+++ 変更後', '@@ -1,4 +1,4 @@',
# ' これはテストです。', ' 1行目', '-2行目', '-3行目',
# '+2行目(変更)', '+4行目']
# 文字列形式で差分を取得
diff_string = get_unified_diff_string(text1, text2)
print(diff_string)
# 出力:
# --- 変更前
#
# +++ 変更後
#
# @@ -1,4 +1,4 @@
#
# これはテストです。
# 1行目
# -2行目
# -3行目
# +2行目(変更)
# +4行目
Context形式の差分を取得
from diff_getter import get_context_diff, get_context_diff_string
# テキストの準備
text1 = "これはテストです。\n1行目\n2行目\n3行目"
text2 = "これはテストです。\n1行目\n2行目(変更)\n4行目"
# リスト形式で差分を取得
diff_list = get_context_diff(text1, text2)
print(diff_list)
# 出力:
# ['*** 変更前', '--- 変更後', '***************',
# '*** 1,4 ****', ' これはテストです。', ' 1行目',
# '! 2行目', '! 3行目', '--- 1,4 ----',
# ' これはテストです。', ' 1行目', '! 2行目(変更)',
# '! 4行目']
# 文字列形式で差分を取得
diff_string = get_context_diff_string(text1, text2)
print(diff_string)
# 出力:
# *** 変更前
# --- 変更後
# ***************
# *** 1,4 ****
# これはテストです。
# 1行目
# ! 2行目
# ! 3行目
# --- 1,4 ----
# これはテストです。
# 1行目
# ! 2行目(変更)
# ! 4行目
コマンドラインツール
# Unified形式で差分を取得
diff-getter unified 古いテキストのファイルパス 新しいテキストのファイルパス
# Context形式で差分を取得
diff-getter context 古いテキストのファイルパス 新しいテキストのファイルパス
開発者向け情報
必要条件
- Python 3.10以上
- uv(依存関係管理ツール)
開発環境のセットアップ
- リポジトリのクローン:
git clone https://github.com/tatn/diff-getter-python.git
cd diff-getter
- 仮想環境の作成と有効化:
uv venv --python 3.10
.venv\Scripts\activate # Windows
- 開発用依存パッケージのインストール:
uv add --dev pytest pytest-cov black ruff mypy build twine hatch
品質管理
テストの実行
# 通常のテスト実行
uv run pytest
# カバレッジレポート付きでテストを実行
uv run pytest --cov=diff_getter tests/
コード品質チェック
# コードフォーマット
uv run black .
# リンター
uv run ruff check .
# 型チェック
uv run mypy src/diff_getter
ライセンス
このプロジェクトはMITライセンスの下で公開されています。
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
diff_getter-0.1.17.tar.gz
(53.0 kB
view details)
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 diff_getter-0.1.17.tar.gz.
File metadata
- Download URL: diff_getter-0.1.17.tar.gz
- Upload date:
- Size: 53.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
681730d0263049a1da4189513a468f771e28662661d77f6447f38ded81377df4
|
|
| MD5 |
bb1d0e1a0728e09baa9c96dbacfa739a
|
|
| BLAKE2b-256 |
b2175c2343419665a5fbd26a2c40c25e3e7a57a9c2d2de38ae6b59780627814e
|
File details
Details for the file diff_getter-0.1.17-py3-none-any.whl.
File metadata
- Download URL: diff_getter-0.1.17-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c954b234c7d3ce3ffb22529f47dcfe123d4a3d38154bd9b6835f7fb128302dda
|
|
| MD5 |
5f2f1a14e4bdc53bf588d66b140420f1
|
|
| BLAKE2b-256 |
000cd4892ecc97a8032f1ad4214c6da805b4fd9c226091456e7a345d2e1b1489
|