summaryrefslogtreecommitdiffstats
path: root/scripts/contrib
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@arm.com>2023-10-27 16:29:41 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-10-27 17:48:11 +0100
commit2cbbe428dbb2fb7d64ad5eb9206f9dea1594ab74 (patch)
treeef3a19cb00d460088210ae7a68ea7642040856a5 /scripts/contrib
parent62c80e3a79beaf521cb6e3e5e036e7aa40358a7c (diff)
downloadpoky-2cbbe428dbb2fb7d64ad5eb9206f9dea1594ab74.tar.gz
scripts/contrib/patchreview: consolidate imports
Move most imports to the top of the file. (From OE-Core rev: d2c287db0739b249604cd1beaa03ec38512ba718) Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/contrib')
-rwxr-xr-xscripts/contrib/patchreview.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/scripts/contrib/patchreview.py b/scripts/contrib/patchreview.py
index 36038d06d2..f95cadab0c 100755
--- a/scripts/contrib/patchreview.py
+++ b/scripts/contrib/patchreview.py
@@ -5,6 +5,15 @@
5# SPDX-License-Identifier: GPL-2.0-only 5# SPDX-License-Identifier: GPL-2.0-only
6# 6#
7 7
8import argparse
9import collections
10import json
11import os
12import os.path
13import pathlib
14import re
15import subprocess
16
8# TODO 17# TODO
9# - option to just list all broken files 18# - option to just list all broken files
10# - test suite 19# - test suite
@@ -35,14 +44,12 @@ def blame_patch(patch):
35 From a patch filename, return a list of "commit summary (author name <author 44 From a patch filename, return a list of "commit summary (author name <author
36 email>)" strings representing the history. 45 email>)" strings representing the history.
37 """ 46 """
38 import subprocess
39 return subprocess.check_output(("git", "log", 47 return subprocess.check_output(("git", "log",
40 "--follow", "--find-renames", "--diff-filter=A", 48 "--follow", "--find-renames", "--diff-filter=A",
41 "--format=%s (%aN <%aE>)", 49 "--format=%s (%aN <%aE>)",
42 "--", patch)).decode("utf-8").splitlines() 50 "--", patch)).decode("utf-8").splitlines()
43 51
44def patchreview(patches): 52def patchreview(patches):
45 import re, os.path
46 53
47 # General pattern: start of line, optional whitespace, tag with optional 54 # General pattern: start of line, optional whitespace, tag with optional
48 # hyphen or spaces, maybe a colon, some whitespace, then the value, all case 55 # hyphen or spaces, maybe a colon, some whitespace, then the value, all case
@@ -192,6 +199,7 @@ Patches in Pending state: %s""" % (total_patches,
192def histogram(results): 199def histogram(results):
193 from toolz import recipes, dicttoolz 200 from toolz import recipes, dicttoolz
194 import math 201 import math
202
195 counts = recipes.countby(lambda r: r.upstream_status, results.values()) 203 counts = recipes.countby(lambda r: r.upstream_status, results.values())
196 bars = dicttoolz.valmap(lambda v: "#" * int(math.ceil(float(v) / len(results) * 100)), counts) 204 bars = dicttoolz.valmap(lambda v: "#" * int(math.ceil(float(v) / len(results) * 100)), counts)
197 for k in bars: 205 for k in bars:
@@ -226,8 +234,6 @@ def count_recipes(layers):
226 return count 234 return count
227 235
228if __name__ == "__main__": 236if __name__ == "__main__":
229 import argparse, subprocess, os, pathlib
230
231 args = argparse.ArgumentParser(description="Patch Review Tool") 237 args = argparse.ArgumentParser(description="Patch Review Tool")
232 args.add_argument("-b", "--blame", action="store_true", help="show blame for malformed patches") 238 args.add_argument("-b", "--blame", action="store_true", help="show blame for malformed patches")
233 args.add_argument("-v", "--verbose", action="store_true", help="show per-patch results") 239 args.add_argument("-v", "--verbose", action="store_true", help="show per-patch results")
@@ -243,7 +249,6 @@ if __name__ == "__main__":
243 analyse(results, want_blame=args.blame, verbose=args.verbose) 249 analyse(results, want_blame=args.blame, verbose=args.verbose)
244 250
245 if args.json: 251 if args.json:
246 import json, os.path, collections
247 if os.path.isfile(args.json): 252 if os.path.isfile(args.json):
248 data = json.load(open(args.json)) 253 data = json.load(open(args.json))
249 else: 254 else: