A CLI tool and Python library for comparing configuration files.
Implemented as part of the Hexlet “Difference Calculator” project.
Gendiff calculates the difference between two configuration files and prints it in one of the supported formats.
Supported input formats:
- JSON (
.json) - YAML (
.yml,.yaml)
Supported output formats:
stylish— human-readable tree view (default)plain— line-by-line change descriptionsjson— structured JSON output
- Python 3.12+
- pip (recommended) or any modern Python package manager
pip install gendiffFrom source (recommended for development)
git clone https://github.com/chifcrow/python-project-50.git
cd python-project-50
python -m venv venv
source venv/bin/activate
pip install -e .[dev]After installation, the gendiff command becomes available.
Help:
gendiff -hCompare two files (default format is stylish):
gendiff file1.json file2.ymlExplicit format:
gendiff --format plain file1.yml file2.yml
gendiff --format json file1.json file2.jsonfrom gendiff import generate_diff
diff = generate_diff(
"path/to/file1.yml",
"path/to/file2.yml",
format_name="plain",
)
print(diff)Shows basic comparison of two flat JSON configuration files.
Demonstrates recursive diff for nested configuration structures.
Shows alternative output formats suitable for logs or machine processing.
Lint:
make lintAuto-fix lint issues:
make lint-fixRun tests:
make testRun tests with coverage.xml generation:
make test-coveragegendiff/
├── __init__.py
├── gendiff.py
├── parser.py
├── diff_builder.py
├── formatters/
│ ├── __init__.py
│ ├── stylish.py
│ ├── plain.py
│ └── json.py
└── scripts/
└── gendiff.py
tests/
└── test_data/
- Python 3.12+
- PyYAML
- pytest / pytest-cov
- Ruff
- GitHub Actions (CI)
- SonarCloud (quality & coverage)
MIT