As a result of the project implementation, we receive a utility Gendiff.
Gendiff - is a console utility and library for comparing two configuration files (JSON or YAML). Highlights the differences between them in convenient formats: stylish, plain, json.
The project implements the following features:
- Output of data differences between the data of two files.
- Output data in flat format.
- Data output in json format.
- Ability to compare flat files (yaml).
- Possibility of recursive comparison.
Supported input file formats JSON, YAML (.yml, .yaml).
Make sure you have Python 3.10+ installed.
git clone https://github.com/pavel-lexrus/python-project-50.git
cd python-project-50
make install или uv pip install -e .
If necessary, install pytest, ruff.
uv pip install pytest
uv pip install ruff
gendiff file1.json file2.json
Default output example (stylish format):
{
common: {
+ follow: false
setting1: Value 1
- setting2: 200
- setting3: true
+ setting3: [complex value]
...
}
}
CLI options:
gendiff [OPTIONS] FILE1 FILE2
Опции:
-f, --format [stylish|plain|json] Формат вывода(по молчанию: stylish)
-h, --help Показать справку и выйти
Output examples:
plain:
gendiff file1.yaml file2.yaml --format plain
text:
Property 'common.setting2' was removed
Property 'common.setting3' was updated. From true to [complex value]
Property 'group1.baz' was updated. From 'bas' to 'bars'
json:
gendiff file1.yaml file2.yaml --format json
Example of use as a library:
from gendiff import generate_diff
diff = generate_diff('file1.yaml', 'file2.yaml', format='plain')
print(diff)