Skip to content

A Python package to generate a diff between two nested structures.

Notifications You must be signed in to change notification settings

mbelveder/gendiff

Repository files navigation

Actions Status Maintainability Test Coverage

Description

A Python package to generate a diff between two nested structures.

gendiff nested_node1.json nested_node2.json

Example

Example input files are located at tests/fixtures.

Supports custom replacers and indent increments for the stylish (default) output:

gendiff nested_node1.json nested_node2.json --replacer  ⏐ --increment 2
{
⏐⏐common: {
⏐⏐⏐⏐node1: val 1
⏐⏐- node2: 200
⏐⏐⏐⏐node3: true
⏐⏐+ node5: got ya
⏐⏐⏐⏐node6: {
⏐⏐⏐⏐⏐⏐doge: {
⏐⏐⏐⏐⏐⏐- wow: 
⏐⏐⏐⏐⏐⏐+ wow: cool
⏐⏐⏐⏐⏐⏐}
⏐⏐⏐⏐- key: val
⏐⏐⏐⏐}
⏐⏐}
}

And the plain output format:

gendiff --format plain nested_node1.json nested_node2.json
Property 'common.node2' was removed
Property 'common.node5' was added with value: 'got ya'
Property 'common.node6.doge.wow' was updated. From '' to 'cool'
Property 'common.node6.key' was removed

The package works both with JSON and YAML files. The json output format shows what happened to each node (added, deleted, changed or unchanged):

asciicast

Created during the Hexlet "Python developer" course without any mentoring.

Installation

Requirements

  • Python 3.11 or higher
  • Git
pip3 install git+https://github.com/mbelveder/gendiff.git

Topics covered:

  • Test-driven development

  • Recursive tree traversal

  • Continuous integration via GitHub Actions

  • Dependency management via Poetry

About

A Python package to generate a diff between two nested structures.

Resources

Stars

Watchers

Forks

Packages

No packages published