Skip to content
Browse files

When applying Changeset 1731

(http://test.kernel.org/trac-autotest/changeset/1731)
the patch was misapplied - actually the patch was meant to create a
utils directory at toplevel dir, however the files were applied at the
autotest root directory, altering the contents of the /common.py file
and thus rendering run_pylint.py not able to run. This patch fix this
issue by:

1 - Restoring the original contents of /common.py
2 - Removing run_pylint.py from toplevel dir to the tools dir;
3 - Creating a new entry point inside of tools

I've moved the scripts to tools instead of the initially proposed utils
toplevel dir because IMHO is not needed to have both a tools and a utils
at toplevel.

Signed-off-by: Lucas Meneghel Rodrigues <lucasmr@br.ibm.com>



git-svn-id: svn://test.kernel.org/autotest/trunk@1743 592f7852-d20e-0410-864c-8624ca9c26a4
  • Loading branch information...
1 parent 0143925 commit 60f316af4291edebb1442ee813fcb38474b8ec5a mbligh committed
Showing with 79 additions and 8 deletions.
  1. +0 −8 common.py
  2. +8 −0 tools/common.py
  3. +71 −0 tools/run_pylint.py
View
8 common.py
@@ -1,13 +1,5 @@
import os, sys
dirname = os.path.dirname(sys.modules[__name__].__file__)
-autotest_dir = os.path.abspath(os.path.join(dirname, ".."))
-client_dir = os.path.join(autotest_dir, "client")
-sys.path.insert(0, client_dir)
-import setup_modules
-sys.path.pop(0)
-setup_modules.setup(base_path=autotest_dir, root_module_name="autotest_lib")
-import os, sys
-dirname = os.path.dirname(sys.modules[__name__].__file__)
autotest_dir = os.path.abspath(dirname)
client_dir = os.path.join(autotest_dir, "client")
sys.path.insert(0, client_dir)
View
8 tools/common.py
@@ -0,0 +1,8 @@
+import os, sys
+dirname = os.path.dirname(sys.modules[__name__].__file__)
+autotest_dir = os.path.abspath(os.path.join(dirname, ".."))
+client_dir = os.path.join(autotest_dir, "client")
+sys.path.insert(0, client_dir)
+import setup_modules
+sys.path.pop(0)
+setup_modules.setup(base_path=autotest_dir, root_module_name="autotest_lib")
View
71 tools/run_pylint.py
@@ -0,0 +1,71 @@
+#!/usr/bin/python -u
+
+import os, sys, fnmatch
+import common
+
+pylintrc_path = os.path.expanduser('~/.pylintrc')
+if not os.path.exists(pylintrc_path):
+ open(pylintrc_path, 'w').close()
+
+import pylint.lint
+from pylint.checkers import imports
+
+ROOT_MODULE = 'autotest_lib.'
+
+# need to put autotest root dir on sys.path so pylint will be happy
+autotest_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
+sys.path.insert(0, autotest_root)
+
+# patch up pylint import checker to handle our importing magic
+RealImportsChecker = imports.ImportsChecker
+
+class CustomImportsChecker(imports.ImportsChecker):
+ def visit_from(self, node):
+ if node.modname.startswith(ROOT_MODULE):
+ node.modname = node.modname[len(ROOT_MODULE):]
+ return RealImportsChecker.visit_from(self, node)
+
+imports.ImportsChecker = CustomImportsChecker
+
+# some files make pylint blow up, so make sure we ignore them
+blacklist = ['/contrib/*', '/frontend/afe/management.py']
+
+# only show errors
+pylint_base_opts = ['--disable-msg-cat=warning,refactor,convention',
+ '--reports=no',
+ '--include-ids=y']
+
+file_list = sys.argv[1:]
+if '--' in file_list:
+ index = file_list.index('--')
+ pylint_base_opts.extend(file_list[index+1:])
+ file_list = file_list[:index]
+
+
+def check_file(file_path):
+ if not file_path.endswith('.py'):
+ return
+ for blacklist_pattern in blacklist:
+ if fnmatch.fnmatch(os.path.abspath(file_path),
+ '*' + blacklist_pattern):
+ return
+ pylint.lint.Run(pylint_base_opts + [file_path])
+
+
+def visit(arg, dirname, filenames):
+ for filename in filenames:
+ check_file(os.path.join(dirname, filename))
+
+
+def check_dir(dir_path):
+ os.path.walk(dir_path, visit, None)
+
+
+if len(file_list) > 0:
+ for path in file_list:
+ if os.path.isdir(path):
+ check_dir(path)
+ else:
+ check_file(path)
+else:
+ check_dir('.')

0 comments on commit 60f316a

Please sign in to comment.
Something went wrong with that request. Please try again.