You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/10/10 18:23:23 UTC
[6/6] mesos git commit: Added a python linter to mesos-style.cpp.
Added a python linter to mesos-style.cpp.
It currently doesn't run over any files in the code base, but we will
be adding the new python CLI in a subsequent commit, which will use
this new linter.
Review: https://reviews.apache.org/r/50910/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c99704ae
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c99704ae
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c99704ae
Branch: refs/heads/master
Commit: c99704ae362657ba69ff367266abd4de2c42a7ca
Parents: c834fa4
Author: Haris Choudhary <ha...@gmail.com>
Authored: Mon Oct 10 10:55:56 2016 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Oct 10 11:19:16 2016 -0700
----------------------------------------------------------------------
support/mesos-style.py | 69 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 67 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/c99704ae/support/mesos-style.py
----------------------------------------------------------------------
diff --git a/support/mesos-style.py b/support/mesos-style.py
index bd4ae38..3a5bec8 100755
--- a/support/mesos-style.py
+++ b/support/mesos-style.py
@@ -191,7 +191,7 @@ class CppLinter(LinterBase):
os.path.join('3rdparty', 'libprocess'),
os.path.join('3rdparty', 'stout')]
- exclude_files = '(protobuf\-2\.4\.1|gmock\-1\.6\.0|glog\-0\.3\.3|boost\-1\.53\.0|libev\-4\.15|java/jni|\.pb\.cc|\.pb\.h|\.md)'
+ exclude_files = '(protobuf\-2\.4\.1|gmock\-1\.6\.0|glog\-0\.3\.3|boost\-1\.53\.0|libev\-4\.15|java/jni|\.pb\.cc|\.pb\.h|\.md|\.virtualenv)'
source_files = '\.(cpp|hpp|cc|h)$'
@@ -243,7 +243,72 @@ class CppLinter(LinterBase):
return p.returncode
+class PyLinter(LinterBase):
+ linter_type = 'Python'
+
+ source_dirs = ['src/cli_new']
+
+ exclude_files = '(protobuf\-2\.4\.1|gmock\-1\.6\.0|glog\-0\.3\.3|boost\-1\.53\.0|libev\-4\.15|java/jni|\.virtualenv)'
+
+ source_files = '\.(py)$'
+
+ comment_prefix = '#'
+
+ def __check_virtualenv(self):
+ cli_dir = os.path.abspath(self.source_dirs[0])
+
+ if not os.path.isdir(os.path.join(cli_dir, '.virtualenv')):
+ print 'Virtualenv not detected... Building'
+
+ p = subprocess.Popen(
+ [os.path.join(cli_dir, 'bootstrap')],
+ stdout=subprocess.PIPE)
+
+ output = ''
+ for line in p.stdout:
+ output += line
+
+ p.wait()
+
+ if p.returncode != 0:
+ sys.stderr.write(output)
+ sys.exit(1);
+
+ def run_lint(self, source_paths):
+ '''
+ Runs pylint over given files.
+
+ https://google.github.io/styleguide/pyguide.html
+ '''
+
+ cli_dir = os.path.abspath(self.source_dirs[0])
+ source_files = ' '.join(source_paths)
+
+ self.__check_virtualenv()
+
+ p = subprocess.Popen(
+ ['. {virtualenv_dir}/bin/activate; \
+ PYTHONPATH={lib_dir}:{bin_dir} pylint --rcfile={config} --ignore={ignore} {files}'.\
+ format(virtualenv_dir=os.path.join(cli_dir, '.virtualenv'),
+ lib_dir=os.path.join(cli_dir,'lib'),
+ bin_dir=os.path.join(cli_dir,'bin'),
+ config=os.path.join(cli_dir, 'pylint.config'),
+ ignore=os.path.join(cli_dir, 'bin', 'mesos'),
+ files=source_files)],
+ shell=True, stdout=subprocess.PIPE)
+
+ num_errors = 0
+ for line in p.stdout:
+ if not line.startswith('*'):
+ num_errors += 1
+ sys.stderr.write(line)
+
+ return num_errors
+
+
if __name__ == '__main__':
cpp_linter = CppLinter()
cpp_errors = cpp_linter.main(sys.argv[1:])
- sys.exit(cpp_errors)
+ py_linter = PyLinter()
+ py_errors = py_linter.main(sys.argv[1:])
+ sys.exit(cpp_errors + py_errors)