void-packages/srcpkgs/gtk-doc/patches/0006-Implement-a-simple-tre...

99 lines
2.4 KiB
Diff
Raw Normal View History

From: Simon McVittie <smcv@debian.org>
Date: Thu, 22 Aug 2019 09:31:19 +0100
Subject: Implement a simple tree structure without using anytree
anytree isn't currently available in Debian or Ubuntu, and seems like a
lot of code just to get a tree data structure. NIH just the bits we need.
---
gtkdoc/mkhtml2.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
tests/mkhtml2.py | 2 +-
2 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/gtkdoc/mkhtml2.py b/gtkdoc/mkhtml2.py
index 91860a7..48d918e 100644
--- a/gtkdoc/mkhtml2.py
+++ b/gtkdoc/mkhtml2.py
@@ -101,7 +101,6 @@ import os
import shutil
import sys
-from anytree import Node, PreOrderIter
from copy import deepcopy
from glob import glob
from lxml import etree
@@ -254,6 +253,57 @@ def get_chunk_titles(module, node, tree_node):
return result
+class PreOrderIter:
+ def __init__(self, node):
+ self.__node = node
+
+ def __iter__(self):
+ yield self.__node
+
+ for child in self.__node.descendants:
+ yield child
+
+
+class Node:
+ def __init__(self, name, parent=None, **kwargs):
+ self.name = name
+ self.__root = None
+ self.__attrs = kwargs
+ self.children = []
+
+ assert parent is None or isinstance(parent, Node)
+ self.parent = parent
+ if parent is not None:
+ self.__root = parent.root
+ parent.children.append(self)
+
+ @property
+ def root(self):
+ return self.__root or self
+
+ @property
+ def descendants(self):
+ ret = []
+
+ for child in self.children:
+ ret.append(child)
+
+ for other in child.descendants:
+ ret.append(other)
+
+ return ret
+
+ def __iter__(self):
+ for child in self.children:
+ yield child
+
+ def __getattr__(self, name):
+ try:
+ return self.__attrs[name]
+ except KeyError as e:
+ raise AttributeError(str(e))
+
+
def chunk(xml_node, module, depth=0, idx=0, parent=None):
"""Chunk the tree.
diff --git a/tests/mkhtml2.py b/tests/mkhtml2.py
index c61ee27..439e7fe 100755
--- a/tests/mkhtml2.py
+++ b/tests/mkhtml2.py
@@ -22,11 +22,11 @@ import logging
import textwrap
import unittest
-from anytree import PreOrderIter
from lxml import etree
from parameterized import parameterized
from gtkdoc import mkhtml2
+from gtkdoc.mkhtml2 import PreOrderIter
class TestChunking(unittest.TestCase):