refscan 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- refscan/__init__.py +18 -0
- refscan/cli/cli.py +27 -0
- refscan/cli/graph.py +80 -0
- refscan/cli/scan.py +211 -0
- refscan/cli/version.py +14 -0
- refscan/grapher.py +173 -0
- refscan/lib/Finder.py +229 -0
- refscan/lib/Reference.py +37 -0
- refscan/lib/ReferenceList.py +206 -0
- refscan/lib/Violation.py +23 -0
- refscan/lib/ViolationList.py +28 -0
- refscan/lib/constants.py +8 -0
- refscan/lib/helpers.py +267 -0
- refscan/scanner.py +369 -0
- refscan/templates/graph.template.html +297 -0
- refscan-0.0.0.dist-info/LICENSE +42 -0
- refscan-0.0.0.dist-info/METADATA +382 -0
- refscan-0.0.0.dist-info/RECORD +20 -0
- refscan-0.0.0.dist-info/WHEEL +4 -0
- refscan-0.0.0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<title>refscan graph</title>
|
|
4
|
+
<style>
|
|
5
|
+
#graph-container {
|
|
6
|
+
width: 100%;
|
|
7
|
+
height: 100vh;
|
|
8
|
+
}
|
|
9
|
+
#metadata-container {
|
|
10
|
+
font-family: sans-serif;
|
|
11
|
+
font-size: 0.8em;
|
|
12
|
+
color: #999999;
|
|
13
|
+
position: absolute;
|
|
14
|
+
bottom: 1em;
|
|
15
|
+
right: 1em;
|
|
16
|
+
text-align: right;
|
|
17
|
+
}
|
|
18
|
+
#metadata-container ul {
|
|
19
|
+
list-style-type: none;
|
|
20
|
+
margin: 0;
|
|
21
|
+
}
|
|
22
|
+
.text-button {
|
|
23
|
+
color: inherit;
|
|
24
|
+
text-decoration: underline;
|
|
25
|
+
background: none;
|
|
26
|
+
border: none;
|
|
27
|
+
margin: 0;
|
|
28
|
+
padding: 0;
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
|
|
35
|
+
<!-- Note: A Python script will replace the `{{ ... }}` placeholders. -->
|
|
36
|
+
<div
|
|
37
|
+
id="graph-data"
|
|
38
|
+
data-graph-data-json-str-base64="{{ graph_data_json_base64 }}"
|
|
39
|
+
data-graph-metadata-json-str-base64="{{ graph_metadata_json_base64 }}"
|
|
40
|
+
></div>
|
|
41
|
+
|
|
42
|
+
<!-- Note: The JavaScript code below will render the above graph data
|
|
43
|
+
as a graph within this HTML element. -->
|
|
44
|
+
<div id="graph-container"></div>
|
|
45
|
+
|
|
46
|
+
<!-- Note: The JavaScript code below will render metadata about the graph,
|
|
47
|
+
within this HTML element. -->
|
|
48
|
+
<div id="metadata-container"></div>
|
|
49
|
+
|
|
50
|
+
<!-- Note: The third-party JavaScript code we're loading here will add a function
|
|
51
|
+
named `cytoscape` to the `window` object (i.e. the global scope).
|
|
52
|
+
Reference: https://js.cytoscape.org/ -->
|
|
53
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.30.1/cytoscape.min.js"
|
|
54
|
+
integrity="sha512-kv2oCpI8sYlWvr442qCcFNgXW9swhLRlDJ/39GlfZLGAWOqgU/Kz30YCYBm0yLumVzRvYEMU6uSxFniGzitKiA=="
|
|
55
|
+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
|
56
|
+
|
|
57
|
+
<script>
|
|
58
|
+
(function () {
|
|
59
|
+
// Note: A Python script will replace the `{{ ... }}` placeholder.
|
|
60
|
+
console.log("Schema version: {{ schema_version }}");
|
|
61
|
+
|
|
62
|
+
// Extract the base64-encoded graph metadata and data from the `graph-data` HTML element.
|
|
63
|
+
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
|
|
64
|
+
let graphMetadata = {};
|
|
65
|
+
let graphData = [];
|
|
66
|
+
const graphDataEl = document.getElementById("graph-data");
|
|
67
|
+
const graphMetadataJsonStrBase64 = graphDataEl.dataset.graphMetadataJsonStrBase64;
|
|
68
|
+
const graphDataJsonStrBase64 = graphDataEl.dataset.graphDataJsonStrBase64;
|
|
69
|
+
|
|
70
|
+
// Base64-decode the graph metadata and parse it as JSON.
|
|
71
|
+
try {
|
|
72
|
+
const graphMetadataJsonStr = atob(graphMetadataJsonStrBase64);
|
|
73
|
+
graphMetadata = JSON.parse(graphMetadataJsonStr);
|
|
74
|
+
console.debug("graphMetadata", graphMetadata);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
alert("Failed to parse metadata.");
|
|
77
|
+
console.debug("graphMetadataJsonStrBase64", graphMetadataJsonStrBase64);
|
|
78
|
+
console.error(error);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Display the graph metadata on the web page.
|
|
82
|
+
const metadataContainerEl = document.getElementById("metadata-container");
|
|
83
|
+
const metadataListEl = document.createElement("ul");
|
|
84
|
+
if (typeof graphMetadata["schema_version"] === "string") {
|
|
85
|
+
const li = document.createElement("li");
|
|
86
|
+
li.textContent = `Schema version ${graphMetadata["schema_version"]}`;
|
|
87
|
+
metadataListEl.appendChild(li);
|
|
88
|
+
}
|
|
89
|
+
if (typeof graphMetadata["app_version"] === "string") {
|
|
90
|
+
const li = document.createElement("li");
|
|
91
|
+
li.textContent = `refscan version ${graphMetadata["app_version"]}`;
|
|
92
|
+
metadataListEl.appendChild(li);
|
|
93
|
+
}
|
|
94
|
+
let subjectSingular = graphMetadata["subject_singular"];
|
|
95
|
+
let subjectPlural = graphMetadata["subject_plural"];
|
|
96
|
+
metadataContainerEl.appendChild(metadataListEl);
|
|
97
|
+
|
|
98
|
+
// Base64-decode the graph data and parse it as JSON.
|
|
99
|
+
try {
|
|
100
|
+
const graphDataJsonStr = atob(graphDataJsonStrBase64);
|
|
101
|
+
graphData = JSON.parse(graphDataJsonStr);
|
|
102
|
+
console.debug("graphData", graphData);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
alert("Failed to parse reference data.");
|
|
105
|
+
console.debug("graphDataJsonStrBase64", graphDataJsonStrBase64);
|
|
106
|
+
console.error(error);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Display the graph on the web page.
|
|
110
|
+
const cy = window.cytoscape({
|
|
111
|
+
container: document.getElementById("graph-container"),
|
|
112
|
+
elements: graphData,
|
|
113
|
+
layout: {
|
|
114
|
+
name: "circle" // For other options, see: https://js.cytoscape.org/#layouts
|
|
115
|
+
},
|
|
116
|
+
style: [
|
|
117
|
+
{
|
|
118
|
+
selector: "node",
|
|
119
|
+
style: {
|
|
120
|
+
label: "data(id)",
|
|
121
|
+
backgroundColor: "#666666",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
selector: "edge",
|
|
126
|
+
style: {
|
|
127
|
+
fontSize: "0.75em",
|
|
128
|
+
textRotation: "autorotate", // parallel to the edge
|
|
129
|
+
lineColor: "#999999",
|
|
130
|
+
targetArrowColor: "#999999",
|
|
131
|
+
targetArrowShape: "triangle",
|
|
132
|
+
curveStyle: "bezier",
|
|
133
|
+
width: 1,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
selector: "node.outgoer",
|
|
138
|
+
style: {
|
|
139
|
+
fontWeight: "bold",
|
|
140
|
+
color: "#00FF00", // text color
|
|
141
|
+
backgroundColor: "#00FF00",
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
selector: "edge.outgoer",
|
|
146
|
+
style: {
|
|
147
|
+
label: "data(label)",
|
|
148
|
+
lineColor: "#00FF00",
|
|
149
|
+
targetArrowColor: "#00FF00",
|
|
150
|
+
width: 3,
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
selector: "node.incomer",
|
|
155
|
+
style: {
|
|
156
|
+
fontWeight: "bold",
|
|
157
|
+
color: "#FFA500", // text color
|
|
158
|
+
backgroundColor: "#FFA500",
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
selector: "edge.incomer",
|
|
163
|
+
style: {
|
|
164
|
+
label: "data(label)",
|
|
165
|
+
lineColor: "#FFA500",
|
|
166
|
+
targetArrowColor: "#FFA500",
|
|
167
|
+
width: 3,
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
selector: "node.incomer.outgoer", // a node that is both an incomer and an outgoer
|
|
172
|
+
style: {
|
|
173
|
+
fontWeight: "bold",
|
|
174
|
+
color: "#00FF00", // text color
|
|
175
|
+
backgroundColor: "#00FF00",
|
|
176
|
+
borderWidth: 3,
|
|
177
|
+
borderStyle: "solid",
|
|
178
|
+
borderColor: "#FFA500",
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
selector: "node.inFocus",
|
|
183
|
+
style: {
|
|
184
|
+
fontWeight: "bold",
|
|
185
|
+
color: "#0000FF", // text color
|
|
186
|
+
backgroundColor: "#0000FF"
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
selector: "node.isAbstract",
|
|
191
|
+
style: {
|
|
192
|
+
opacity: 0.5,
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
selector: "edge.isAbstract",
|
|
197
|
+
style: {
|
|
198
|
+
opacity: 0.5,
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Whenever the user clicks on a node, highlight that node, all the edges
|
|
205
|
+
// emanating from that node, and all the nodes those edges point to.
|
|
206
|
+
//
|
|
207
|
+
// References:
|
|
208
|
+
// - https://js.cytoscape.org/#events
|
|
209
|
+
// - https://js.cytoscape.org/#collection/traversing
|
|
210
|
+
//
|
|
211
|
+
cy.bind("tap", "node", (event) => {
|
|
212
|
+
// Remove classes from all elements.
|
|
213
|
+
cy.elements()
|
|
214
|
+
.removeClass("outgoer")
|
|
215
|
+
.removeClass("incomer")
|
|
216
|
+
.removeClass("inFocus");
|
|
217
|
+
|
|
218
|
+
// Apply classes to the target node, the arrows coming out of it,
|
|
219
|
+
// and the nodes those arrows point to.
|
|
220
|
+
event.target
|
|
221
|
+
.addClass("inFocus")
|
|
222
|
+
.outgoers()
|
|
223
|
+
.addClass("outgoer");
|
|
224
|
+
|
|
225
|
+
// Apply classes to the arrows pointing to the target node,
|
|
226
|
+
// and the nodes those arrows are coming out of.
|
|
227
|
+
event.target
|
|
228
|
+
.incomers()
|
|
229
|
+
.addClass("incomer");
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Whenever the user double-clicks on a node, un-highlight all elements.
|
|
233
|
+
cy.bind("dbltap", "node", (event) => {
|
|
234
|
+
// Remove classes from all elements.
|
|
235
|
+
cy.elements()
|
|
236
|
+
.removeClass("outgoer")
|
|
237
|
+
.removeClass("incomer")
|
|
238
|
+
.removeClass("inFocus");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Sets up a text button that can be used to toggle the visibility of
|
|
243
|
+
* nodes that represent abstract things.
|
|
244
|
+
*/
|
|
245
|
+
function setupAbstractNodeVisibilityToggler() {
|
|
246
|
+
// Get a collection of all nodes that represent abstract things.
|
|
247
|
+
// Note: For conciseness, we refer to them as "abstract nodes" here.
|
|
248
|
+
// Reference: https://js.cytoscape.org/#eles.filter
|
|
249
|
+
const abstractNodes = cy.filter(function(el, idx, allEls) {
|
|
250
|
+
return el.isNode() && el.data("is_abstract");
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// If there are any abstract nodes, give them (and the edges connected to them)
|
|
254
|
+
// a specific "stylesheet" class and set up their visibility toggler.
|
|
255
|
+
if (abstractNodes.length > 0) {
|
|
256
|
+
abstractNodes.addClass("isAbstract");
|
|
257
|
+
abstractNodes.connectedEdges().addClass("isAbstract");
|
|
258
|
+
|
|
259
|
+
// Set up a clickable element that can be used to show/hide the abstract nodes.
|
|
260
|
+
// Note: When a node gets hidden, its connected edges will be automatically hidden also.
|
|
261
|
+
const strings = {
|
|
262
|
+
prefix: `Abstract ${subjectPlural} are `,
|
|
263
|
+
visible: "visible",
|
|
264
|
+
hidden: "hidden",
|
|
265
|
+
};
|
|
266
|
+
let removedNodes = cy.collection(); // initially empty
|
|
267
|
+
const prefixEl = document.createElement("span");
|
|
268
|
+
prefixEl.textContent =strings.prefix;
|
|
269
|
+
const togglerEl = document.createElement("button");
|
|
270
|
+
togglerEl.classList.add("text-button");
|
|
271
|
+
togglerEl.title = "Toggle visibility";
|
|
272
|
+
const togglerTextEl = document.createElement("span");
|
|
273
|
+
togglerTextEl.textContent = strings.visible;
|
|
274
|
+
togglerEl.appendChild(togglerTextEl);
|
|
275
|
+
togglerEl.addEventListener("click", () => {
|
|
276
|
+
if (removedNodes.length > 0) {
|
|
277
|
+
// Add them back into the graph.
|
|
278
|
+
removedNodes.restore();
|
|
279
|
+
removedNodes = cy.collection();
|
|
280
|
+
togglerTextEl.textContent = strings.visible;
|
|
281
|
+
} else {
|
|
282
|
+
// Remove them from the graph, but save them in memory.
|
|
283
|
+
removedNodes = cy.remove(abstractNodes);
|
|
284
|
+
togglerTextEl.textContent = strings.hidden;
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
metadataContainerEl.appendChild(prefixEl);
|
|
288
|
+
metadataContainerEl.appendChild(togglerEl);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Set up the abstract node visibility toggler.
|
|
293
|
+
setupAbstractNodeVisibilityToggler();
|
|
294
|
+
})();
|
|
295
|
+
</script>
|
|
296
|
+
</body>
|
|
297
|
+
</html>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Refscan Copyright (c) 2024, The Regents of the University of California,
|
|
2
|
+
through Lawrence Berkeley National Laboratory (subject to receipt of any
|
|
3
|
+
required approvals from the U.S. Dept. of Energy). All rights reserved.
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
(1) Redistributions of source code must retain the above copyright notice,
|
|
9
|
+
this list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
(2) Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
documentation and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
(3) Neither the name of the University of California, Lawrence Berkeley
|
|
16
|
+
National Laboratory, U.S. Dept. of Energy nor the names of its contributors
|
|
17
|
+
may be used to endorse or promote products derived from this software
|
|
18
|
+
without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
24
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
25
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
26
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
27
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
28
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
29
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
30
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
31
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
32
|
+
|
|
33
|
+
You are under no obligation whatsoever to provide any bug fixes, patches,
|
|
34
|
+
or upgrades to the features, functionality or performance of the source
|
|
35
|
+
code ("Enhancements") to anyone; however, if you choose to make your
|
|
36
|
+
Enhancements available either publicly, or directly to Lawrence Berkeley
|
|
37
|
+
National Laboratory, without imposing a separate written license agreement
|
|
38
|
+
for such Enhancements, then you hereby grant the following license: a
|
|
39
|
+
non-exclusive, royalty-free perpetual license to install, use, modify,
|
|
40
|
+
prepare derivative works, incorporate into other computer software,
|
|
41
|
+
distribute, and sublicense such enhancements or derivative works thereof,
|
|
42
|
+
in binary and source code form.
|