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ライセンスの下で公開されています。
Metadata
Release files for diff-getter 0.1.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| diff_getter-0.1.18.tar.gz | 53.0 kB | Without provenance | Details for diff_getter-0.1.18.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| diff_getter-0.1.18-py3-none-any.whl | Python 3 | none | any | Details for diff_getter-0.1.18-py3-none-any.whl |
Total release size: 58.5 kB
Release files / diff_getter-0.1.18.tar.gz
| Download URL | diff_getter-0.1.18.tar.gz |
|---|---|
| Size | 53.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7bff84245f5693ff47aa9f416816cdf81d2ff789d63c18c8d172a425aa29c5da
|
|
BLAKE2b-256 checksum How to use checksums |
d8e94b0f8bfdc55c86309db0a36e3bfdf02082ecbc1bea555cc48eeaa39d1760
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.21
|
Release files / diff_getter-0.1.18-py3-none-any.whl
| Download URL | diff_getter-0.1.18-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b75bd8a870cff509757f62ad3803cbb685d79c91d0c389b42393ab9bc06abd8e
|
|
BLAKE2b-256 checksum How to use checksums |
a482ab28518e8ecf3b53016c77267fc7b83c39a4ab4730be9d4219e265bc831a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.21
|
Security for diff-getter 0.1.18
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.