diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..136e0e3
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,15 @@
+repos:
+- repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v4.5.0
+ hooks:
+ - id: check-added-large-files
+ args: [--maxkb=8192]
+ - id: check-yaml
+ - id: end-of-file-fixer
+ - id: trailing-whitespace
+- repo: https://github.com/astral-sh/ruff-pre-commit
+ rev: v0.1.8
+ hooks:
+ - id: ruff
+ args: [--fix, --exit-non-zero-on-fix]
+ - id: ruff-format
diff --git a/algorithm_tree.py b/algorithm_tree.py
index 79d4c47..8b18506 100644
--- a/algorithm_tree.py
+++ b/algorithm_tree.py
@@ -19,7 +19,7 @@
import re
-class Node():
+class Node:
def __init__(self, info=[]):
self.parent = None
self.level = 0
@@ -33,6 +33,7 @@ def to_list_int(node, lst):
lst.append(node)
for nd in node.children:
to_list_int(nd, lst)
+
to_list_int(self, res)
return res
@@ -47,6 +48,7 @@ def find_all_int(node, cond, res):
res.append(node)
for nd in node.children:
find_all_int(nd, cond, res)
+
result = []
find_all_int(self, cond, result)
return result
@@ -57,6 +59,7 @@ def find_in_depth_int(node, cond, res):
res[0] = node
for nd in node.children:
find_in_depth_int(nd, cond, res)
+
result = [None]
find_in_depth_int(self, cond, result)
return result[0]
@@ -71,6 +74,7 @@ def find_first_int(node, cond, res):
return
for nd in node.children:
find_first_int(nd, cond, res)
+
result = []
find_first_int(self, cond, result)
return result[0]
@@ -91,6 +95,7 @@ def apply_int(nd, func):
nd.info = func(nd.info)
for ch in nd.children:
apply_int(ch, func)
+
root = self.clone()
apply_int(root, func)
return root
@@ -128,9 +133,8 @@ def apply_multiple_trees(trees, check, func):
def parseLine(line):
- res = re.search('ThreadID=([0-9]*), AlgorithmName=(.*), StartTime=([0-9]*), EndTime=([0-9]*)', line)
- return {"thread_id" : res.group(1), "name" : res.group(2),
- "start" : int(res.group(3)), "finish" : int(res.group(4))}
+ res = re.search("ThreadID=([0-9]*), AlgorithmName=(.*), StartTime=([0-9]*), EndTime=([0-9]*)", line)
+ return {"thread_id": res.group(1), "name": res.group(2), "start": int(res.group(3)), "finish": int(res.group(4))}
def fromFile(fileName):
@@ -146,28 +150,41 @@ def fromFile(fileName):
def cmp_to_key(mycmp):
- 'Convert a cmp= function into a key= function'
+ "Convert a cmp= function into a key= function"
+
class K:
- def __init__(self, obj, *args):
+ def __init__(self, obj, *args): # noqa: ARG002
self.obj = obj
+
def __lt__(self, other):
return mycmp(self.obj, other.obj) < 0
+
def __gt__(self, other):
return mycmp(self.obj, other.obj) > 0
+
def __eq__(self, other):
return mycmp(self.obj, other.obj) == 0
+
def __le__(self, other):
return mycmp(self.obj, other.obj) <= 0
+
def __ge__(self, other):
return mycmp(self.obj, other.obj) >= 0
+
def __ne__(self, other):
return mycmp(self.obj, other.obj) != 0
+
return K
+
def toTrees(records):
- recs = sorted(records, key = cmp_to_key(lambda x, y: x["start"] - y["start"] if x["start"] != y["start"] else y["finish"] - x["finish"]))
+ recs = sorted(
+ records,
+ key=cmp_to_key(lambda x, y: x["start"] - y["start"] if x["start"] != y["start"] else y["finish"] - x["finish"]),
+ )
+
def rec_to_node(r, counter):
- return Node([r["name"] + " " + str(counter), r["start"], r["finish"], counter ])
+ return Node([r["name"] + " " + str(counter), r["start"], r["finish"], counter])
heads = []
counter = dict()
diff --git a/mantid-profiler.py b/mantid-profiler.py
index a05cb42..5319fb3 100644
--- a/mantid-profiler.py
+++ b/mantid-profiler.py
@@ -15,13 +15,15 @@
# along with this program. If not, see
" % (percTot,rawTime,percRaw)
+ boxText += "s (%.1f%%) | %.1fs (%.1f%%)
" % (percTot, rawTime, percRaw)
if node.parent is not None:
boxText += "Parent: " + node.parent.info[0] + "
"
@@ -135,7 +135,7 @@ def treeNodeToHtml(node, lmax, sync_time, header, count, tot_time):
outputString += "x: [%f, %f, %f, %f, %f],\n" % (x0, x0, x2, x1, x1)
outputString += "y: [%f, %f, %f, %f, %f],\n" % (y0, y1, y1, y1, y0)
outputString += "fill: 'tozeroy',\n"
- outputString += "fillcolor: 'rgb(%i,%i,%i)',\n" % (color[0],color[1],color[2])
+ outputString += "fillcolor: 'rgb(%i,%i,%i)',\n" % (color[0], color[1], color[2])
outputString += "line: {\n"
outputString += "color: '#000000',\n"
outputString += "dash: 'solid',\n"
@@ -146,10 +146,13 @@ def treeNodeToHtml(node, lmax, sync_time, header, count, tot_time):
# If the background color is too bright, make the font color black.
# Default font color is white
if color[3] > 180:
- textcolor = '#000000'
+ textcolor = "#000000"
else:
- textcolor = '#ffffff'
- outputString += "text: ['', '', '%s', '', ''],\n" % (textcolor, base_url, node.info[0].split()[0], node.info[0])
+ textcolor = "#ffffff"
+ outputString += (
+ "text: ['', '', '%s', '', ''],\n"
+ % (textcolor, base_url, node.info[0].split()[0], node.info[0])
+ )
outputString += "textposition: 'top',\n"
outputString += "hovertext: '" + boxText + "',\n"
outputString += "hoverinfo: 'text',\n"
@@ -163,15 +166,15 @@ def treeNodeToHtml(node, lmax, sync_time, header, count, tot_time):
# Generate HTML interactive plot with Plotly library
-def htmlProfile(filename=None, x=None, data=None, records=None, fill_factor=0,
- nthreads=0, lmax=0, sync_time=0, header=None):
-
- htmlFile = open(filename,'w')
+def htmlProfile(
+ filename=None, x=None, data=None, records=None, fill_factor=0, nthreads=0, lmax=0, sync_time=0, header=None
+):
+ htmlFile = open(filename, "w")
htmlFile.write("