Skip to content

Best approach to use graphtage to create a "diff" of an already existing tree? #75

@SamWilsn

Description

@SamWilsn

Hey! Sorry for the broad scope of this question, but I'm having some trouble wrapping my head around how to use this library to generate a "diff" or "patch" for an already existing tree structure.

Background

We're writing a specification, and want to highlight changes between versions of the specification. Currently we use sphinx and a bunch of custom tooling to render the documents. You can see what the current documentation looks like here.

We've hit a few walls with this approach and have decided to move to a custom solution. You can see what that looks like over here.

The new tooling, docc, represents each document as a tree of nodes. This is what we want to calculate a diff between. For example, this is how we represent Python types.

Goal

I'd like to take two document trees, perform some magic with graphtage, and get out a third tree representing what's changed. Here's a really simple example:

Before After Output
graph TD;
    A-->B
    A-->C
Loading
graph TD;
    A-->B
    A-->D
Loading
graph TD;
    A-->B
    A-->Diff
    Diff-->|removed| C
    Diff-->|added| D
Loading

Issues

I've tried the Diffing In-Memory Python Objects approach, but received a utf-8 decoding error.

I've tried subclassing LeafNode and ContainerNode, but I'm not familiar enough with graphtage to implement them correctly.

Current Approach

My current approach is to map my tree objects into FixedKeyDictNode instances, then back into my tree objects. Now I'm stuck figuring out how to convert the EditedTreeNode instances into the Diff(before, after) style node from the above example. What would you suggest?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions