Skip to content

chifcrow/python-project-50

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gendiff — Difference Calculator

A CLI tool and Python library for comparing configuration files.
Implemented as part of the Hexlet “Difference Calculator” project.


Status

Actions Status Quality Gate Status Coverage


Description

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 descriptions
  • json — structured JSON output

Requirements

  • Python 3.12+
  • pip (recommended) or any modern Python package manager

Installation

From PyPI (when published)

pip install gendiff

From 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.

Usage

CLI

Help:

gendiff -h

Compare two files (default format is stylish):

gendiff file1.json file2.yml

Explicit format:

gendiff --format plain file1.yml file2.yml
gendiff --format json file1.json file2.json

Library

from gendiff import generate_diff

diff = generate_diff(
    "path/to/file1.yml",
    "path/to/file2.yml",
    format_name="plain",
)

print(diff)

Examples

1. Comparing flat JSON files (default stylish format)

Shows basic comparison of two flat JSON configuration files.

asciicast


2. Comparing nested YAML files (stylish format)

Demonstrates recursive diff for nested configuration structures.

asciicast


3. Different output formats (plain and json)

Shows alternative output formats suitable for logs or machine processing.

asciicast

asciicast

Development

Lint:

make lint

Auto-fix lint issues:

make lint-fix

Run tests:

make test

Run tests with coverage.xml generation:

make test-coverage

Project Structure

gendiff/
├── __init__.py
├── gendiff.py
├── parser.py
├── diff_builder.py
├── formatters/
│   ├── __init__.py
│   ├── stylish.py
│   ├── plain.py
│   └── json.py
└── scripts/
    └── gendiff.py
tests/
└── test_data/

Technologies

  • Python 3.12+
  • PyYAML
  • pytest / pytest-cov
  • Ruff
  • GitHub Actions (CI)
  • SonarCloud (quality & coverage)

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published