https://github.com/williamfzc/difile
lightweight diff-file library with difflib
https://github.com/williamfzc/difile
diff file-diff python
Last synced: 5 months ago
JSON representation
lightweight diff-file library with difflib
- Host: GitHub
- URL: https://github.com/williamfzc/difile
- Owner: williamfzc
- License: mit
- Created: 2020-07-01T10:07:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-12T13:53:05.000Z (over 5 years ago)
- Last Synced: 2025-02-04T19:15:18.877Z (about 1 year ago)
- Topics: diff, file-diff, python
- Language: Python
- Homepage:
- Size: 41 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# difile

[](https://codecov.io/gh/williamfzc/difile)
lightweight diff-file library with difflib
## goal
- something like git-diff but without git
- programmable
- dirs and files
## installation
```bash
pip install difile
```
## usage
### command line
```bash
difile compare_file file1.txt file2.txt
difile compare_dir dir1 dir2
```
or a short name:
```bash
difile cf file1.txt file2.txt
difile cd dir1 dir2
```
### script
compare files and get a `List[Line]` object:
```python
from difile import Difile
difile = Difile()
diff_obj = difile.compare_file("dirs/dir1/file1.txt", "dirs/dir2/file1.txt")
```
and you can see what happened between files:
```python
for each in diff_obj:
print(each.line_no, each.code, each.file_path, each.content.strip())
```
get:
```text
1 - tests/dirs/dir1/file1.txt no
1 + tests/dirs/dir2/file1.txt difile
2 - tests/dirs/dir1/file1.txt this is file1
2 + tests/dirs/dir2/file1.txt that is file1
3 - tests/dirs/dir1/file1.txt random
3 + tests/dirs/dir2/file1.txt
4 - tests/dirs/dir1/file1.txt aha
```
- line 1: `no` -> `difile`
- line 2: `this is file1` -> `that is file1`
- line 3: `random` -> enter
- line 4: has been removed
of course compare dirs:
```python
from difile import Difile
difile = Difile()
diff_obj = difile.compare_dir("dirs/dir1", "dirs/dir2")
```
you will get a `List[List[Line]]` object.
## license
[MIT](LICENSE)