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.16.tar.gz
(52.3 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.16.tar.gz.
File metadata
- Download URL: diff_getter-0.1.16.tar.gz
- Upload date:
- Size: 52.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbb284e4cc1ecad328134d5e144522b07cbde1ff19282c5696d45284c71afc9a
|
|
| MD5 |
37f1e37fc0023b4f6fdbe1069c5adad1
|
|
| BLAKE2b-256 |
7cbc7681507c446f8c94d816f0759a0b0f7d59dbada2896a88aec973c1e431cb
|
File details
Details for the file diff_getter-0.1.16-py3-none-any.whl.
File metadata
- Download URL: diff_getter-0.1.16-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d3fcf083b814b5e82e4e2eb5d057108926083c4a74eada9d322bb8b75ccc55b
|
|
| MD5 |
722108bff774caddb6eef18f4cfd871a
|
|
| BLAKE2b-256 |
123e09a8b70a34f42be994427e44675595b29a9fabe25b2eb186ce1d92571d17
|