aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-03-28 12:12:34 -0400
committerDavid Robillard <d@drobilla.net>2023-04-05 09:45:15 -0400
commit4bfbbd357d4e12522f5e8ba0a0ebc3bfc037b706 (patch)
tree89ece7e437e820a01560522f738f8ee9a8070afb /scripts
parentd25435678a9ced05bd3a8c78ae3534c230fdfc5d (diff)
downloadserd-4bfbbd357d4e12522f5e8ba0a0ebc3bfc037b706.tar.gz
serd-4bfbbd357d4e12522f5e8ba0a0ebc3bfc037b706.tar.bz2
serd-4bfbbd357d4e12522f5e8ba0a0ebc3bfc037b706.zip
Clean up Python scripts and add a formatting test
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/serd_bench.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/scripts/serd_bench.py b/scripts/serd_bench.py
index 2000ee6b..89d34e1f 100755
--- a/scripts/serd_bench.py
+++ b/scripts/serd_bench.py
@@ -1,17 +1,28 @@
#!/usr/bin/env python
-# Copyright 2018-2022 David Robillard <d@drobilla.net>
+# Copyright 2018-2023 David Robillard <d@drobilla.net>
# SPDX-License-Identifier: ISC
+""""Benchmark RDF reading and writing commands."""
+
+# pylint: disable=consider-using-f-string
+# pylint: disable=consider-using-with
+# pylint: disable=import-outside-toplevel
+# pylint: disable=invalid-name
+# pylint: disable=redefined-outer-name
+# pylint: disable=too-many-locals
+# pylint: disable=unspecified-encoding
+
import argparse
import csv
import itertools
import math
-import matplotlib
import os
import subprocess
import sys
+import matplotlib
+
class WorkingDirectory:
"Scoped context for changing working directory"
@@ -30,16 +41,18 @@ class WorkingDirectory:
os.chdir(self.original_dir)
-def filename(n):
+def filename(num):
"Filename for a generated file with n statements"
- return "gen%d.ttl" % n
+ return "gen%d.ttl" % num
def gen(sp2b_dir, n_min, n_max, step):
"Generate files with n_min ... n_max statements if they are not present"
with WorkingDirectory(sp2b_dir) as directory:
for n in range(n_min, n_max + step, step):
- out_path = os.path.join(directory.original_dir, "build", filename(n))
+ out_path = os.path.join(
+ directory.original_dir, "build", filename(n)
+ )
if not os.path.exists(out_path):
subprocess.call(["./sp2b_gen", "-t", str(n), out_path])
@@ -84,7 +97,7 @@ def plot(in_file, out_filename, x_label, y_label, y_max=None):
matplotlib.use("agg")
import matplotlib.pyplot as plt
- plt.rcParams.update({'font.size': 7})
+ plt.rcParams.update({"font.size": 7})
fig_height = 1.8
dashes = get_dashes()
@@ -92,7 +105,7 @@ def plot(in_file, out_filename, x_label, y_label, y_max=None):
reader = csv.reader(in_file, delimiter="\t")
header = next(reader)
- cols = [x for x in zip(*list(reader))]
+ cols = list(zip(*list(reader)))
plt.clf()
fig = plt.figure(figsize=(fig_height * math.sqrt(2), fig_height))
@@ -194,7 +207,7 @@ def plot_results():
if __name__ == "__main__":
ap = argparse.ArgumentParser(
usage="%(prog)s [OPTION]... SP2B_DIR",
- description="Benchmark RDF reading and writing commands\n",
+ description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
example: