Skip to main content

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

Metadata

Release files for treediffer 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for treediffer 0.0.3
File Size Uploaded Provenance
treediffer-0.0.3.tar.gz 26.8 kB Without provenance Details

Release files / treediffer-0.0.3.tar.gz

Download URL treediffer-0.0.3.tar.gz
Size 26.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d91d60c1fba9be37c6a150cee96abfb332c8a6efd6478555c3b9b40c4d2a8724
BLAKE2b-256 checksum
How to use checksums
50097e7a9ee52ddac6c75ae3a3a9480ef4222de520f99bca1cff433f36f78f12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9

Security for treediffer 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page