aboutsummaryrefslogtreecommitdiff
path: root/dev_scripts
diff options
context:
space:
mode:
authorSergei Trofimov <sergei.trofimov@arm.com>2018-07-05 16:37:28 +0100
committerMarc Bonnici <marc.bonnici@arm.com>2018-07-06 14:39:41 +0100
commit88c5005b382dd3e4ad101056a097088c1b665cf8 (patch)
tree6db0f90a6785988483e61aa3c1c7bd1384d7d911 /dev_scripts
parent651adaaa573d4925551459e9d9e567eea5980949 (diff)
dev_scripts: pylint: ignore errors per subdir
Add the ability to ignore specific pylint errors on per-subpackage or per-module basis by adding a plugin that checks the path of the module against pre-defined sub-paths and inserts disable tags as needed.
Diffstat (limited to 'dev_scripts')
-rwxr-xr-xdev_scripts/pylint9
-rw-r--r--dev_scripts/pylint_plugins.py45
2 files changed, 50 insertions, 4 deletions
diff --git a/dev_scripts/pylint b/dev_scripts/pylint
index 4e216809..060dfba7 100755
--- a/dev_scripts/pylint
+++ b/dev_scripts/pylint
@@ -42,12 +42,13 @@ if [ "$result" == "2" ]; then
fi
THIS_DIR="`dirname \"$0\"`"
+CWD=$PWD
+pushd $THIS_DIR > /dev/null
if [[ "$target" == "" ]]; then
- pushd $THIS_DIR/.. > /dev/null
for dir in "${DEFAULT_DIRS[@]}"; do
- pylint --rcfile extras/pylintrc $dir
+ PYTHONPATH=. pylint --rcfile ../extras/pylintrc --load-plugins pylint_plugins $CWD/$dir
done
- popd > /dev/null
else
- pylint --rcfile $THIS_DIR/../extras/pylintrc $target
+ PYTHONPATH=. pylint --rcfile ../extras/pylintrc --load-plugins pylint_plugins $CWD/$target
fi
+popd > /dev/null
diff --git a/dev_scripts/pylint_plugins.py b/dev_scripts/pylint_plugins.py
new file mode 100644
index 00000000..f01942d8
--- /dev/null
+++ b/dev_scripts/pylint_plugins.py
@@ -0,0 +1,45 @@
+from astroid import MANAGER
+from astroid import scoped_nodes
+
+
+IGNORE_ERRORS = {
+ ('attribute-defined-outside-init', ): [
+ 'wa.workloads',
+ 'wa.instruments',
+ 'wa.output_procesors',
+ ]
+}
+
+
+def register(linter):
+ pass
+
+
+def transform(mod):
+ for errors, paths in IGNORE_ERRORS.items():
+ for path in paths:
+ if path in mod.name:
+ text = mod.stream().read()
+ if not text.strip():
+ return
+
+ text = text.split('\n')
+ # NOTE: doing it this way because the "correct" approach below does not
+ # work. We can get away with this, because in well-formated WA files,
+ # the initial line is the copyright header's blank line.
+ if 'pylint:' in text[0]:
+ msg = 'pylint directive found on the first line of {}; please move to below copyright header'
+ raise RuntimeError(msg.format(mod.name))
+ if text[0].strip() and text[0][0] != '#':
+ msg = 'first line of {} is not a comment; is the copyright header missing?'
+ raise RuntimeError(msg.format(mod.name))
+ text[0] = '# pylint: disable={}'.format(','.join(errors))
+ mod.file_bytes = '\n'.join(text)
+
+ # This is what *should* happen, but doesn't work.
+ # text.insert(0, '# pylint: disable=attribute-defined-outside-init')
+ # mod.file_bytes = '\n'.join(text)
+ # mod.tolineno += 1
+
+
+MANAGER.register_transform(scoped_nodes.Module, transform)