跳转到主要内容

一个用于计算树形数据结构差异的实用函数库。

项目描述

treediffer

version build codecov pypi docs

一个用于计算树形数据结构差异的实用函数库。

安装

pip install treediffer

使用示例

给定使用./contentcuration/manage.py archivechannel ...生成的maintreestagingtree的Studio频道JSON存档版本,您可以使用以下方法计算它们之间的树差异

>>> 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
}

此代码示例使用基于工作室预置的“高级”API,该API设置了所有必要的查找(node_id、content_id、parent、assetment_items等),因此差异逻辑将正常工作。请参阅 examples/studiodiffferpoc.py以获取完整的脚本。

Ricecooker树差异

请参考 examples/ricecookerdiffpoc.py 以获取类似的脚本,该脚本比较在每次内容集成脚本运行后保存在 chefdata/trees/ 目录中的 ricecooker 树。

替代的 diff 格式

使用 format="restructured" 对简化的 diff 进行后处理,并将添加和删除分组到逻辑子树中(例如,如果整个主题被删除,则显示为子树)。这是在命令行打印(如示例脚本中所示)时的默认设置。

使用 format="raw" 在简化和解检测之前查看 diff(用于调试)。

测试

pytest

pytest --cov=src/treediffer tests/

文档

访问 https://treediffer.readthedocs.io/ 获取有关该功能如何工作的更多信息。特别是,请参阅 https://treediffer.readthedocs.io/en/latest/diff_formats.html 了解生成 diff 的结构细节,以及 https://treediffer.readthedocs.io/en/latest/design.html 了解 API 的高级使用。

待办事项

  • 完成基本功能
  • 添加 ricecooker differ 的示例
  • 添加 studio differ 的示例
  • 添加厨房测试,用于组合删除、添加、移动和修改

项目详情


下载文件

为您的平台下载文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

treediffer-0.0.3.tar.gz (26.8 kB 查看哈希值)

由...