Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

treediffer

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

treediffer

A library of utility functions for coputing diffs between tree-like data structures.

  • 0.0.3
  • PyPI
  • Socket score

Maintainers
2

treediffer

version build codecov pypi docs

A library of utility functions for computing diffs between tree-like data structures.

Installation

pip install treediffer

Usage example

Given studio tree JSON-archive versions of the maintree and the stagingtree of a Studio channel generated using ./contentcuration/manage.py archivechannel ..., you can compute the tree diff between them using:

>>> from treediffer import treediff
>>> diff = treediff(maintree, stagingtree, preset="studio", format="simplified")
>>> diff
{
  "nodes_deleted": [...],   # content_ids gone in stagingtree
  "nodes_added": [...],     # new content_ids in stagingtree
  "nodes_moved": [...],     # same content_id but different node_id
  "nodes_modified": [...],  # same node_id, but changes in node attributes
}

This code examples uses the "high level" API based on the studio preset that set all the necessary lookups (node_id, content_id, parent, assetment_items, etc.) so the diffing logic will work. See examples/studiodiffferpoc.py for full script.

Ricecooker tree diffing

See examples/ricecookerdiffpoc.py for similar script that diffs ricecooker trees that get saved in chefdata/trees/ dir after each content integration script runs.

Alternative diff formats

Use format="restructured" to post-process the simplified diff and group additions and deletions into logical subtrees (e.g. if whole topic is deleted, show as subtree). This is the default when printing on command line as in the example scripts.

Use format="raw" to see the diff before simplification and move detection (for debugging).

Tests

pytest

and

pytest --cov=src/treediffer tests/

Documentation

Visit https://treediffer.readthedocs.io/ for more info about how this works In particular see https://treediffer.readthedocs.io/en/latest/diff_formats.html for the the details about the structure of the diffs produced and https://treediffer.readthedocs.io/en/latest/design.html for API advanced usage.

TODOs

  • Finish basic functionality
  • add example ricecooker differ
  • add example studio differ
  • Add kitchen sink test for combined deleted, added, moved, and modified

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc