Repository: mesos Updated Branches: refs/heads/master 8ffc35414 -> 102a36304
Created virtual environment for linters in /support. This change affects the Python linter but not the C++ linter as we use a customized version of cpplint that we cannot get using pip. Review: https://reviews.apache.org/r/63581/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/102a3630 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/102a3630 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/102a3630 Branch: refs/heads/master Commit: 102a36304ca1a78384b8841c94b122a4a93e5a4e Parents: 8ffc354 Author: Armand Grillet <agril...@mesosphere.io> Authored: Thu Nov 9 16:10:22 2017 +0100 Committer: Kevin Klues <klue...@gmail.com> Committed: Thu Nov 9 16:14:14 2017 +0100 ---------------------------------------------------------------------- src/python/pylint.config | 31 ---------- support/.gitignore | 1 + support/build-virtualenv | 65 ++++++++++++++++++++ support/mesos-style.py | 122 ++++++++++++++++++-------------------- support/pip-requirements.txt | 1 + support/pylint.config | 31 ++++++++++ 6 files changed, 157 insertions(+), 94 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/102a3630/src/python/pylint.config ---------------------------------------------------------------------- diff --git a/src/python/pylint.config b/src/python/pylint.config deleted file mode 100644 index f74f553..0000000 --- a/src/python/pylint.config +++ /dev/null @@ -1,31 +0,0 @@ -[MASTER] -ignore=.git - -[MESSAGES CONTROL] -disable=I0011,no-self-use,fixme,invalid-name,file-ignored - -[REPORTS] -reports=no - -[BASIC] -bad-functions=input,file -good-names=i,j,k,f,ip,_ -min-public-methods=0 - -[FORMAT] -max-line-length=80 -indent-string=' ' - -[DESIGN] -max-branches=20 -max-returns=100 - -[EXCEPTIONS] -overgeneral-exceptions= - -[TYPECHECK] -ignored-modules = netifaces - -[SIMILARITIES] -ignore-imports=yes -min-similarity-lines=100 http://git-wip-us.apache.org/repos/asf/mesos/blob/102a3630/support/.gitignore ---------------------------------------------------------------------- diff --git a/support/.gitignore b/support/.gitignore new file mode 100644 index 0000000..a21a0f9 --- /dev/null +++ b/support/.gitignore @@ -0,0 +1 @@ +.virtualenv http://git-wip-us.apache.org/repos/asf/mesos/blob/102a3630/support/build-virtualenv ---------------------------------------------------------------------- diff --git a/support/build-virtualenv b/support/build-virtualenv new file mode 100755 index 0000000..b46a86a --- /dev/null +++ b/support/build-virtualenv @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +# This script sets up a Python virtualenv for the Web UI. This creates +# a new virtualenv and installs nodeenv inside the virtualenv. + +set -e +trap "exit 1" INT + +CURRDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +: ${VIRTUALENV_NAME:="linters"} +: ${VIRTUALENV_DIRECTORY:="${CURRDIR}/.virtualenv"} + +: ${PYTHON:="$(which python)"} +: ${VIRTUALENV:="$(which virtualenv)"} + +OLD_PYTHONPATH="${PYTHONPATH}" +PYTHONPATH="" + +# If we already have a virtual environment activated, +# bail out and advise the user to deactivate. +OLD_VIRTUAL_ENV="${VIRTUAL_ENV}" +if [ "${OLD_VIRTUAL_ENV}" != "" ]; then + echo "Please deactivate your current virtual environment in order to continue!" + echo "source deactivate" + exit 1 +fi + +# Verify that python and virtualenv are installed. +if [ "${PYTHON}" = "" ]; then + echo "You must have python installed in order to continue..." + exit 1 +fi + +if [ "${VIRTUALENV}" = "" ]; then + # Search for a locally installed virtualenv. + # See https://docs.python.org/2/library/site.html#site.USER_SITE for details. + VIRTUALENV=$(${PYTHON} -c "import site; print site.USER_SITE")/virtualenv.py + + if [ ! -f "${VIRTUALENV}" ]; then + echo "You must have virtualenv installed in order to continue..." + exit 1 + fi +fi + +PYTHON_MAJOR=$(${PYTHON} -c 'import sys; print(sys.version_info[0])') +PYTHON_MINOR=$(${PYTHON} -c 'import sys; print(sys.version_info[1])') + +if [ "${PYTHON_MAJOR}" != "2" ] || [ "${PYTHON_MINOR}" -lt "6" ]; then + echo "You must be running python 2.6 or 2.7 in order to continue." + echo "Consider running as 'PYTHON=python2 ./bootstrap' or similar." + exit 1 +fi + +# Set up a virtual environment for the linters. +${PYTHON} ${VIRTUALENV} --python=${PYTHON} \ + --clear \ + --no-site-packages \ + --prompt="(${VIRTUALENV_NAME}) " \ + ${VIRTUALENV_DIRECTORY} || true + +source ${VIRTUALENV_DIRECTORY}/bin/activate +pip install --upgrade pip +pip install -r ${CURRDIR}/pip-requirements.txt +deactivate http://git-wip-us.apache.org/repos/asf/mesos/blob/102a3630/support/mesos-style.py ---------------------------------------------------------------------- diff --git a/support/mesos-style.py b/support/mesos-style.py index b2fdac9..96030f2 100755 --- a/support/mesos-style.py +++ b/support/mesos-style.py @@ -153,62 +153,6 @@ class LinterBase(object): return error_count - def should_build_virtualenv(self, modified_files): - """ - Check if we should build the virtual environment required. - This is the case if the requirements of the environment - have changed or if the support script is run with no - arguments (meaning that the entire codebase should be linted). - """ - work_dir = os.path.abspath(self.source_dirs[0]) - - if not os.path.isdir(os.path.join(work_dir, '.virtualenv')): - print 'Virtualenv not detected... building' - return True - - # NOTE: If the file list is empty, we are linting the entire - # codebase. We should always rebuild the virtualenv in this case. - if len(modified_files) <= 0: - return True - - basenames = [] - if modified_files: - basenames = [os.path.basename(path) for path in modified_files] - - if 'pip-requirements.txt' in basenames: - print 'The "pip-requirements.txt" file has changed.' - return True - - # This is only useful for the Python linter. - if 'mesos.bash_completion' in basenames: - print 'The "mesos.bash_completion" file has changed.' - return True - - return False - - def build_virtualenv(self): - """ - Rebuild the virtualenv by running a bootstrap script. - This will exit the program if there is a failure. - """ - work_dir = os.path.abspath(self.source_dirs[0]) - - print 'Rebuilding virtualenv...' - - process = subprocess.Popen( - [os.path.join(work_dir, 'bootstrap')], - stdout=subprocess.PIPE) - - output = '' - for line in process.stdout: - output += line - - process.wait() - - if process.returncode != 0: - sys.stderr.write(output) - sys.exit(1) - def main(self, modified_files): """ This function takes a list of files and lints them for the @@ -315,6 +259,9 @@ class CppLinter(LinterBase): 'whitespace/todo'] rules_filter = '--filter=-,+' + ',+'.join(active_rules) + + # We do not use a version of cpplint available through pip as + # we use a custom version (see cpplint.path) to lint C++ files. process = subprocess.Popen( ['python', 'support/cpplint.py', rules_filter] + source_paths, stderr=subprocess.PIPE, @@ -356,9 +303,10 @@ class PyLinter(LinterBase): self.config = { 'bootstrap_dir': cli_dir, - 'virtualenv_dir': os.path.join(cli_dir, '.virtualenv'), - 'pylint_config': os.path.join(python_dir, 'pylint.config'), - 'pylint_cmd': os.path.join(cli_dir, '.virtualenv', 'bin', 'pylint') + 'virtualenv_dir': os.path.join(support_dir, '.virtualenv'), + 'pylint_config': os.path.join(support_dir, 'pylint.config'), + 'pylint_cmd': os.path.join( + support_dir, '.virtualenv', 'bin', 'pylint') } self.source_dirs = [cli_dir, lib_dir, support_dir] @@ -394,14 +342,62 @@ class PyLinter(LinterBase): return num_errors def main(self, modified_files): - """Override main to rebuild our virtualenv if necessary.""" - if self.should_build_virtualenv(modified_files): - self.build_virtualenv() - return super(PyLinter, self).main(modified_files) +def should_build_virtualenv(modified_files): + """ + Check if we should build the virtual environment required. + This is the case if the requirements of the environment + have changed or if the support script is run with no + arguments (meaning that the entire codebase should be linted). + """ + if not os.path.isdir(os.path.join('support', '.virtualenv')): + print 'Virtualenv not detected... building' + return True + + # NOTE: If the file list is empty, we are linting the entire + # codebase. We should always rebuild the virtualenv in this case. + if not modified_files: + return True + + basenames = [os.path.basename(path) for path in modified_files] + + if 'pip-requirements.txt' in basenames: + print 'The "pip-requirements.txt" file has changed.' + return True + + if 'build-virtualenv' in basenames: + print 'The "build-virtualenv" file has changed.' + return True + + return False + + +def build_virtualenv(): + """ + Rebuild the virtualenv by running a bootstrap script. + This will exit the program if there is a failure. + """ + print 'Rebuilding virtualenv...' + + process = subprocess.Popen( + [os.path.join('support', 'build-virtualenv')], + stdout=subprocess.PIPE) + + output = '' + for line in process.stdout: + output += line + + process.wait() + + if process.returncode != 0: + sys.stderr.write(output) + sys.exit(1) + if __name__ == '__main__': + if should_build_virtualenv(sys.argv[1:]): + build_virtualenv() CPP_LINTER = CppLinter() CPP_ERRORS = CPP_LINTER.main(sys.argv[1:]) PY_LINTER = PyLinter() http://git-wip-us.apache.org/repos/asf/mesos/blob/102a3630/support/pip-requirements.txt ---------------------------------------------------------------------- diff --git a/support/pip-requirements.txt b/support/pip-requirements.txt new file mode 100644 index 0000000..6ae67d0 --- /dev/null +++ b/support/pip-requirements.txt @@ -0,0 +1 @@ +pylint==1.6.4 http://git-wip-us.apache.org/repos/asf/mesos/blob/102a3630/support/pylint.config ---------------------------------------------------------------------- diff --git a/support/pylint.config b/support/pylint.config new file mode 100644 index 0000000..f74f553 --- /dev/null +++ b/support/pylint.config @@ -0,0 +1,31 @@ +[MASTER] +ignore=.git + +[MESSAGES CONTROL] +disable=I0011,no-self-use,fixme,invalid-name,file-ignored + +[REPORTS] +reports=no + +[BASIC] +bad-functions=input,file +good-names=i,j,k,f,ip,_ +min-public-methods=0 + +[FORMAT] +max-line-length=80 +indent-string=' ' + +[DESIGN] +max-branches=20 +max-returns=100 + +[EXCEPTIONS] +overgeneral-exceptions= + +[TYPECHECK] +ignored-modules = netifaces + +[SIMILARITIES] +ignore-imports=yes +min-similarity-lines=100