1 |
commit: 7c03e29ee878fea8283373764506032386552d19 |
2 |
Author: Matoro Mahri <matoro <AT> users <DOT> noreply <DOT> github <DOT> com> |
3 |
AuthorDate: Thu Oct 6 02:58:53 2022 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Oct 30 09:33:28 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7c03e29e |
7 |
|
8 |
media-gfx/xdot: add tests |
9 |
|
10 |
Bug: https://bugs.gentoo.org/873490 |
11 |
Signed-off-by: Matoro Mahri <matoro <AT> users.noreply.github.com> |
12 |
Closes: https://github.com/gentoo/gentoo/pull/27653 |
13 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
14 |
|
15 |
.../xdot/files/backport-2ace1a1-issue-92.patch | 151 +++++++++++++++++++++ |
16 |
.../xdot/{xdot-9999.ebuild => xdot-1.2-r1.ebuild} | 17 ++- |
17 |
media-gfx/xdot/xdot-9999.ebuild | 12 +- |
18 |
3 files changed, 176 insertions(+), 4 deletions(-) |
19 |
|
20 |
diff --git a/media-gfx/xdot/files/backport-2ace1a1-issue-92.patch b/media-gfx/xdot/files/backport-2ace1a1-issue-92.patch |
21 |
new file mode 100644 |
22 |
index 000000000000..8cb76a43fe55 |
23 |
--- /dev/null |
24 |
+++ b/media-gfx/xdot/files/backport-2ace1a1-issue-92.patch |
25 |
@@ -0,0 +1,151 @@ |
26 |
+https://github.com/jrfonseca/xdot.py/issues/92 |
27 |
+https://bugs.gentoo.org/873490 |
28 |
+ |
29 |
+From 2ace1a12d78423d9e7af20fdb0bca34827010408 Mon Sep 17 00:00:00 2001 |
30 |
+From: Jose Fonseca <jose.r.fonseca@×××××.com> |
31 |
+Date: Tue, 28 Sep 2021 13:19:49 +0100 |
32 |
+Subject: [PATCH] Handle xdot backslashes correctly. |
33 |
+ |
34 |
+Irrespectively of graphviz version. |
35 |
+ |
36 |
+Fixes https://github.com/jrfonseca/xdot.py/issues/92 |
37 |
+--- |
38 |
+ tests/issue_92_a.dot | 3 +++ |
39 |
+ tests/issue_92_b.dot | 3 +++ |
40 |
+ xdot/dot/parser.py | 26 +++++++++++++++++++++----- |
41 |
+ xdot/ui/window.py | 11 ++++++++++- |
42 |
+ 4 files changed, 37 insertions(+), 6 deletions(-) |
43 |
+ create mode 100644 tests/issue_92_a.dot |
44 |
+ create mode 100644 tests/issue_92_b.dot |
45 |
+ |
46 |
+diff --git a/tests/issue_92_a.dot b/tests/issue_92_a.dot |
47 |
+new file mode 100644 |
48 |
+index 0000000..ea486b0 |
49 |
+--- /dev/null |
50 |
++++ b/tests/issue_92_a.dot |
51 |
+@@ -0,0 +1,3 @@ |
52 |
++digraph { |
53 |
++ 1 [label="a\\00"] |
54 |
++} |
55 |
+diff --git a/tests/issue_92_b.dot b/tests/issue_92_b.dot |
56 |
+new file mode 100644 |
57 |
+index 0000000..ba90566 |
58 |
+--- /dev/null |
59 |
++++ b/tests/issue_92_b.dot |
60 |
+@@ -0,0 +1,3 @@ |
61 |
++digraph { |
62 |
++ 1 [label="a\\b"] |
63 |
++} |
64 |
+diff --git a/xdot/dot/parser.py b/xdot/dot/parser.py |
65 |
+index 4244e03..6578c23 100644 |
66 |
+--- a/xdot/dot/parser.py |
67 |
++++ b/xdot/dot/parser.py |
68 |
+@@ -14,8 +14,11 @@ |
69 |
+ # along with this program. If not, see <http://www.gnu.org/licenses/>. |
70 |
+ # |
71 |
+ import colorsys |
72 |
++import re |
73 |
+ import sys |
74 |
+ |
75 |
++from distutils.version import LooseVersion |
76 |
++ |
77 |
+ from .lexer import ParseError, DotLexer |
78 |
+ |
79 |
+ from ..ui.colors import lookup_color |
80 |
+@@ -85,7 +88,14 @@ class XDotAttrParser: |
81 |
+ - http://www.graphviz.org/doc/info/output.html#d:xdot |
82 |
+ """ |
83 |
+ |
84 |
+- def __init__(self, parser, buf): |
85 |
++ def __init__(self, parser, buf, broken_backslashes): |
86 |
++ |
87 |
++ # `\` should be escaped as `\\`, but older versions of graphviz xdot |
88 |
++ # output failed to properly escape it. See also |
89 |
++ # https://github.com/jrfonseca/xdot.py/issues/92 |
90 |
++ if not broken_backslashes: |
91 |
++ buf = re.sub(br'\\(.)', br'\1', buf) |
92 |
++ |
93 |
+ self.parser = parser |
94 |
+ self.buf = buf |
95 |
+ self.pos = 0 |
96 |
+@@ -427,10 +437,16 @@ class XDotParser(DotParser): |
97 |
+ |
98 |
+ XDOTVERSION = '1.7' |
99 |
+ |
100 |
+- def __init__(self, xdotcode): |
101 |
++ def __init__(self, xdotcode, graphviz_version=None): |
102 |
+ lexer = DotLexer(buf=xdotcode) |
103 |
+ DotParser.__init__(self, lexer) |
104 |
+ |
105 |
++ # https://github.com/jrfonseca/xdot.py/issues/92 |
106 |
++ self.broken_backslashes = False |
107 |
++ if graphviz_version is not None and \ |
108 |
++ LooseVersion(graphviz_version) < LooseVersion("2.46.0"): |
109 |
++ self.broken_backslashes = True |
110 |
++ |
111 |
+ self.nodes = [] |
112 |
+ self.edges = [] |
113 |
+ self.shapes = [] |
114 |
+@@ -480,7 +496,7 @@ def handle_graph(self, attrs): |
115 |
+ |
116 |
+ for attr in ("_draw_", "_ldraw_", "_hdraw_", "_tdraw_", "_hldraw_", "_tldraw_"): |
117 |
+ if attr in attrs: |
118 |
+- parser = XDotAttrParser(self, attrs[attr]) |
119 |
++ parser = XDotAttrParser(self, attrs[attr], self.broken_backslashes) |
120 |
+ self.shapes.extend(parser.parse()) |
121 |
+ |
122 |
+ def handle_node(self, id, attrs): |
123 |
+@@ -502,7 +518,7 @@ def handle_node(self, id, attrs): |
124 |
+ shapes = [] |
125 |
+ for attr in ("_draw_", "_ldraw_"): |
126 |
+ if attr in attrs: |
127 |
+- parser = XDotAttrParser(self, attrs[attr]) |
128 |
++ parser = XDotAttrParser(self, attrs[attr], self.broken_backslashes) |
129 |
+ shapes.extend(parser.parse()) |
130 |
+ try: |
131 |
+ url = attrs['URL'] |
132 |
+@@ -525,7 +541,7 @@ def handle_edge(self, src_id, dst_id, attrs): |
133 |
+ shapes = [] |
134 |
+ for attr in ("_draw_", "_ldraw_", "_hdraw_", "_tdraw_", "_hldraw_", "_tldraw_"): |
135 |
+ if attr in attrs: |
136 |
+- parser = XDotAttrParser(self, attrs[attr]) |
137 |
++ parser = XDotAttrParser(self, attrs[attr], self.broken_backslashes) |
138 |
+ shapes.extend(parser.parse()) |
139 |
+ if shapes: |
140 |
+ src = self.node_by_name[src_id] |
141 |
+diff --git a/xdot/ui/window.py b/xdot/ui/window.py |
142 |
+index 893bd1d..e27f000 100644 |
143 |
+--- a/xdot/ui/window.py |
144 |
++++ b/xdot/ui/window.py |
145 |
+@@ -56,6 +56,7 @@ class DotWidget(Gtk.DrawingArea): |
146 |
+ } |
147 |
+ |
148 |
+ filter = 'dot' |
149 |
++ graphviz_version = None |
150 |
+ |
151 |
+ def __init__(self): |
152 |
+ Gtk.DrawingArea.__init__(self) |
153 |
+@@ -100,6 +101,7 @@ def error_dialog(self, message): |
154 |
+ |
155 |
+ def set_filter(self, filter): |
156 |
+ self.filter = filter |
157 |
++ self.graphviz_version = None |
158 |
+ |
159 |
+ def run_filter(self, dotcode): |
160 |
+ if not self.filter: |
161 |
+@@ -153,7 +155,14 @@ def set_dotcode(self, dotcode, filename=None, center=True): |
162 |
+ |
163 |
+ def set_xdotcode(self, xdotcode, center=True): |
164 |
+ assert isinstance(xdotcode, bytes) |
165 |
+- parser = XDotParser(xdotcode) |
166 |
++ if self.graphviz_version is None: |
167 |
++ stdout = subprocess.check_output([self.filter, '-V'], stderr=subprocess.STDOUT) |
168 |
++ stdout = stdout.rstrip() |
169 |
++ mo = re.match(br'^.* - .* version (?P<version>.*) \(.*\)$', stdout) |
170 |
++ assert mo |
171 |
++ self.graphviz_version = mo.group('version').decode('ascii') |
172 |
++ |
173 |
++ parser = XDotParser(xdotcode, graphviz_version=self.graphviz_version) |
174 |
+ self.graph = parser.parse() |
175 |
+ self.zoom_image(self.zoom_ratio, center=center) |
176 |
+ |
177 |
|
178 |
diff --git a/media-gfx/xdot/xdot-9999.ebuild b/media-gfx/xdot/xdot-1.2-r1.ebuild |
179 |
similarity index 66% |
180 |
copy from media-gfx/xdot/xdot-9999.ebuild |
181 |
copy to media-gfx/xdot/xdot-1.2-r1.ebuild |
182 |
index 646fd464d2bd..579a8e03216a 100644 |
183 |
--- a/media-gfx/xdot/xdot-9999.ebuild |
184 |
+++ b/media-gfx/xdot/xdot-1.2-r1.ebuild |
185 |
@@ -2,7 +2,7 @@ |
186 |
# Distributed under the terms of the GNU General Public License v2 |
187 |
|
188 |
EAPI=7 |
189 |
-PYTHON_COMPAT=( python3_{8..11} ) |
190 |
+PYTHON_COMPAT=( python3_{8..10} ) |
191 |
|
192 |
MY_PN=xdot.py |
193 |
EGIT_REPO_URI="https://github.com/jrfonseca/${MY_PN}" |
194 |
@@ -11,24 +11,35 @@ if [[ ${PV} = 9999* ]]; then |
195 |
GIT_ECLASS="git-r3" |
196 |
SRC_URI="" |
197 |
else |
198 |
- KEYWORDS="~amd64 ~arm ~arm64 ~ia64 ~ppc ~ppc64 ~x86" |
199 |
+ KEYWORDS="amd64 arm arm64 ~hppa ~ia64 ppc ~ppc64 ~riscv ~sparc x86" |
200 |
MY_P="${MY_PN}-${PV}" |
201 |
S="${WORKDIR}/${MY_P}" |
202 |
SRC_URI="https://github.com/jrfonseca/${MY_PN}/archive/${PV}.tar.gz -> ${P}.tar.gz" |
203 |
fi |
204 |
|
205 |
-inherit ${GIT_ECLASS} distutils-r1 |
206 |
+inherit ${GIT_ECLASS} distutils-r1 virtualx |
207 |
|
208 |
DESCRIPTION="Interactive viewer for Graphviz dot files" |
209 |
HOMEPAGE="https://github.com/jrfonseca/xdot.py" |
210 |
|
211 |
LICENSE="LGPL-2+" |
212 |
SLOT="0" |
213 |
+PATCHES=( "${FILESDIR}/backport-2ace1a1-issue-92.patch" ) |
214 |
|
215 |
DEPEND=" |
216 |
dev-python/numpy[${PYTHON_USEDEP}] |
217 |
dev-python/pycairo[${PYTHON_USEDEP}] |
218 |
dev-python/pygobject:3[${PYTHON_USEDEP}] |
219 |
media-gfx/graphviz |
220 |
+ test? ( x11-libs/gtk+:3 ) |
221 |
" |
222 |
RDEPEND="${DEPEND}" |
223 |
+ |
224 |
+run_test() { |
225 |
+ cd tests && "${EPYTHON}" ../test.py *.dot graphs/*.gv |
226 |
+ return "${?}" |
227 |
+} |
228 |
+ |
229 |
+python_test() { |
230 |
+ virtx run_test |
231 |
+} |
232 |
|
233 |
diff --git a/media-gfx/xdot/xdot-9999.ebuild b/media-gfx/xdot/xdot-9999.ebuild |
234 |
index 646fd464d2bd..b0e3b6d5c63e 100644 |
235 |
--- a/media-gfx/xdot/xdot-9999.ebuild |
236 |
+++ b/media-gfx/xdot/xdot-9999.ebuild |
237 |
@@ -17,7 +17,7 @@ else |
238 |
SRC_URI="https://github.com/jrfonseca/${MY_PN}/archive/${PV}.tar.gz -> ${P}.tar.gz" |
239 |
fi |
240 |
|
241 |
-inherit ${GIT_ECLASS} distutils-r1 |
242 |
+inherit ${GIT_ECLASS} distutils-r1 virtualx |
243 |
|
244 |
DESCRIPTION="Interactive viewer for Graphviz dot files" |
245 |
HOMEPAGE="https://github.com/jrfonseca/xdot.py" |
246 |
@@ -30,5 +30,15 @@ DEPEND=" |
247 |
dev-python/pycairo[${PYTHON_USEDEP}] |
248 |
dev-python/pygobject:3[${PYTHON_USEDEP}] |
249 |
media-gfx/graphviz |
250 |
+ test? ( x11-libs/gtk+:3 ) |
251 |
" |
252 |
RDEPEND="${DEPEND}" |
253 |
+ |
254 |
+run_test() { |
255 |
+ cd tests && "${EPYTHON}" ../test.py *.dot graphs/*.gv |
256 |
+ return "${?}" |
257 |
+} |
258 |
+ |
259 |
+python_test() { |
260 |
+ virtx run_test |
261 |
+} |