You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bb...@apache.org on 2018/09/04 07:29:03 UTC
[mesos] branch master updated: Fixed all Python linting issues.
This is an automated email from the ASF dual-hosted git repository.
bbannier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push:
new 16a4266 Fixed all Python linting issues.
16a4266 is described below
commit 16a4266737458fcae21c8585ff2c127ff93617c4
Author: Armand Grillet <ag...@mesosphere.io>
AuthorDate: Tue Sep 4 09:23:08 2018 +0200
Fixed all Python linting issues.
Review: https://reviews.apache.org/r/68608/
---
src/python/cli_new/bin/main.py | 2 +-
src/python/cli_new/bin/settings.py | 2 +-
src/python/cli_new/lib/cli/config.py | 2 +-
src/python/cli_new/lib/cli/docopt.py | 2 +-
src/python/cli_new/lib/cli/plugins/__init__.py | 2 +-
src/python/cli_new/lib/cli/plugins/agent/main.py | 2 +-
src/python/cli_new/lib/cli/plugins/base.py | 12 +++---
src/python/cli_new/lib/cli/plugins/task/main.py | 2 +-
src/python/cli_new/lib/cli/tests/__init__.py | 2 +-
src/python/cli_new/lib/cli/tests/agent.py | 3 +-
src/python/cli_new/lib/cli/tests/base.py | 11 +++--
src/python/cli_new/lib/cli/tests/task.py | 3 +-
src/python/cli_new/lib/cli/util.py | 4 +-
src/python/lib/mesos/http.py | 2 +-
src/python/lib/tests/test_http.py | 6 +--
support/apply-reviews.py | 6 +--
support/generate-endpoint-help.py | 3 +-
support/python3/apply-reviews.py | 11 +++--
support/python3/common.py | 2 +-
support/python3/generate-endpoint-help.py | 2 +-
support/python3/mesos-style.py | 34 ++++++++++------
support/python3/push-commits.py | 52 ++++++++++++------------
support/python3/test-upgrade.py | 4 +-
support/verify-reviews.py | 2 +-
24 files changed, 88 insertions(+), 85 deletions(-)
diff --git a/src/python/cli_new/bin/main.py b/src/python/cli_new/bin/main.py
index b6f9fab..27783ca 100644
--- a/src/python/cli_new/bin/main.py
+++ b/src/python/cli_new/bin/main.py
@@ -67,7 +67,7 @@ def autocomplete(cmds, plugins, config, argv):
comp_words = list(cmds.keys()) + ["help"]
comp_words = cli.util.completions(comp_words, current_word, argv)
- if comp_words != None:
+ if comp_words is not None:
return (option, comp_words)
plugin = cli.util.get_module(plugins, argv[0])
diff --git a/src/python/cli_new/bin/settings.py b/src/python/cli_new/bin/settings.py
index f501fef..3de3387 100644
--- a/src/python/cli_new/bin/settings.py
+++ b/src/python/cli_new/bin/settings.py
@@ -28,7 +28,7 @@ import os
# file will be autogenerated and inserted into the PYTHONPATH.
# When this happens we import it to set the VERSION.
try:
- # pylint: disable=F0401,W0611
+ # pylint: disable=import-error,unused-import,no-name-in-module
from version import VERSION
except Exception:
VERSION = "Development"
diff --git a/src/python/cli_new/lib/cli/config.py b/src/python/cli_new/lib/cli/config.py
index 92ff3eb..c88952b 100644
--- a/src/python/cli_new/lib/cli/config.py
+++ b/src/python/cli_new/lib/cli/config.py
@@ -28,7 +28,7 @@ from cli.constants import DEFAULT_MASTER_PORT
from cli.exceptions import CLIException
-class Config(object):
+class Config():
"""
The Config class loads the configuration file on initialization and has
one method for each element that can be specified in the config file.
diff --git a/src/python/cli_new/lib/cli/docopt.py b/src/python/cli_new/lib/cli/docopt.py
index 4dedd77..c624175 100644
--- a/src/python/cli_new/lib/cli/docopt.py
+++ b/src/python/cli_new/lib/cli/docopt.py
@@ -49,7 +49,7 @@ once docopt supports the "program" argument natively.
import os
import sys
-# pylint: disable=F0401
+# pylint: disable=import-error
from docopt import docopt as real_docopt, DocoptExit
diff --git a/src/python/cli_new/lib/cli/plugins/__init__.py b/src/python/cli_new/lib/cli/plugins/__init__.py
index e743772..58890f2 100644
--- a/src/python/cli_new/lib/cli/plugins/__init__.py
+++ b/src/python/cli_new/lib/cli/plugins/__init__.py
@@ -18,5 +18,5 @@
Plugins Module
"""
-# pylint: disable=W0401
+# pylint: disable=wildcard-import
from .base import *
diff --git a/src/python/cli_new/lib/cli/plugins/agent/main.py b/src/python/cli_new/lib/cli/plugins/agent/main.py
index 4ebf8cd..fc62d9f 100644
--- a/src/python/cli_new/lib/cli/plugins/agent/main.py
+++ b/src/python/cli_new/lib/cli/plugins/agent/main.py
@@ -18,7 +18,7 @@
The agent plugin.
"""
-import cli.http as http
+from cli import http
from cli.exceptions import CLIException
from cli.plugins import PluginBase
diff --git a/src/python/cli_new/lib/cli/plugins/base.py b/src/python/cli_new/lib/cli/plugins/base.py
index e01a7b2..6cba828 100644
--- a/src/python/cli_new/lib/cli/plugins/base.py
+++ b/src/python/cli_new/lib/cli/plugins/base.py
@@ -66,11 +66,11 @@ Description:
"""
-class PluginBase(object):
+class PluginBase():
"""
Base class from which all CLI plugins should inherit.
"""
- # pylint: disable=R0903
+ # pylint: disable=too-few-public-methods
COMMANDS = {}
def __setup__(self, command, argv):
@@ -80,7 +80,7 @@ class PluginBase(object):
return sys.modules[self.__module__]
def __init__(self, settings, config):
- # pylint: disable=C0103
+ # pylint: disable=invalid-name
self.PLUGIN_NAME = PLUGIN_NAME
self.PLUGIN_CLASS = PLUGIN_CLASS
self.VERSION = VERSION
@@ -103,7 +103,8 @@ class PluginBase(object):
self.config = config
def __autocomplete__(self, command, current_word, argv):
- # pylint: disable=W0612,W0613,R0201
+ # pylint: disable=unused-variable,unused-argument,
+ # attribute-defined-outside-init
return ("default", [])
def __autocomplete_base__(self, current_word, argv):
@@ -112,11 +113,10 @@ class PluginBase(object):
# <command>
comp_words = list(self.COMMANDS.keys())
comp_words = cli.util.completions(comp_words, current_word, argv)
- if comp_words != None:
+ if comp_words is not None:
return (option, comp_words)
# <args>...
- # pylint: disable=R0204
comp_words = self.__autocomplete__(argv[0], current_word, argv[1:])
# In general, we expect a tuple to be returned from __autocomplete__,
diff --git a/src/python/cli_new/lib/cli/plugins/task/main.py b/src/python/cli_new/lib/cli/plugins/task/main.py
index f9d6826..644e256 100644
--- a/src/python/cli_new/lib/cli/plugins/task/main.py
+++ b/src/python/cli_new/lib/cli/plugins/task/main.py
@@ -18,7 +18,7 @@
The task plugin.
"""
-import cli.http as http
+from cli import http
from cli.exceptions import CLIException
from cli.plugins import PluginBase
diff --git a/src/python/cli_new/lib/cli/tests/__init__.py b/src/python/cli_new/lib/cli/tests/__init__.py
index b7c825f..144cb33 100644
--- a/src/python/cli_new/lib/cli/tests/__init__.py
+++ b/src/python/cli_new/lib/cli/tests/__init__.py
@@ -18,7 +18,7 @@
Mesos CLI unit tests module.
"""
-# pylint: disable=W0401
+# pylint: disable=wildcard-import
from .base import *
from .agent import *
diff --git a/src/python/cli_new/lib/cli/tests/agent.py b/src/python/cli_new/lib/cli/tests/agent.py
index 6e5e565..31e3e3f 100644
--- a/src/python/cli_new/lib/cli/tests/agent.py
+++ b/src/python/cli_new/lib/cli/tests/agent.py
@@ -18,9 +18,8 @@
Agent plugin tests.
"""
-import cli.http as http
-
from cli import config
+from cli import http
from cli.plugins.agent.main import Agent as AgentPlugin
diff --git a/src/python/cli_new/lib/cli/tests/base.py b/src/python/cli_new/lib/cli/tests/base.py
index f58d616..3fb471c 100644
--- a/src/python/cli_new/lib/cli/tests/base.py
+++ b/src/python/cli_new/lib/cli/tests/base.py
@@ -28,7 +28,7 @@ import unittest
import parse
-import cli.http as http
+from cli import http
from cli.tests.constants import TEST_AGENT_IP
from cli.tests.constants import TEST_AGENT_PORT
@@ -68,17 +68,16 @@ class CLITestCase(unittest.TestCase):
if os.path.isdir(build_dir):
return build_dir
- else:
- raise CLIException("The Mesos build directory"
- " does not exist: {path}"
- .format(path=build_dir))
+ raise CLIException("The Mesos build directory"
+ " does not exist: {path}"
+ .format(path=build_dir))
# This value is set to the correct path when running tests/main.py. We
# set it here to make sure that CLITestCase has a MESOS_BUILD_DIR member.
CLITestCase.MESOS_BUILD_DIR = ""
-class Executable(object):
+class Executable():
"""
This class defines the base class for launching an executable for
the CLI unit tests. It will be subclassed by (at least) a
diff --git a/src/python/cli_new/lib/cli/tests/task.py b/src/python/cli_new/lib/cli/tests/task.py
index 3a57094..b54ade5 100644
--- a/src/python/cli_new/lib/cli/tests/task.py
+++ b/src/python/cli_new/lib/cli/tests/task.py
@@ -18,9 +18,8 @@
Task plugin tests.
"""
-import cli.http as http
-
from cli import config
+from cli import http
from cli.plugins.task.main import Task as TaskPlugin
diff --git a/src/python/cli_new/lib/cli/util.py b/src/python/cli_new/lib/cli/util.py
index b740431..7cec7e4 100644
--- a/src/python/cli_new/lib/cli/util.py
+++ b/src/python/cli_new/lib/cli/util.py
@@ -28,7 +28,7 @@ import textwrap
from kazoo.client import KazooClient
-import cli.http as http
+from cli import http
from cli.exceptions import CLIException
@@ -279,7 +279,7 @@ def zookeeper_resolve_leader(addresses, path):
return address
-class Table(object):
+class Table():
"""
Defines a custom table structure for printing to the terminal.
"""
diff --git a/src/python/lib/mesos/http.py b/src/python/lib/mesos/http.py
index 8a5a368..cd15877 100644
--- a/src/python/lib/mesos/http.py
+++ b/src/python/lib/mesos/http.py
@@ -76,7 +76,7 @@ def simple_urljoin(base, other):
return '/'.join([base.rstrip('/'), other.lstrip('/')])
-class Resource(object):
+class Resource():
"""
Encapsulate the context for an HTTP resource.
diff --git a/src/python/lib/tests/test_http.py b/src/python/lib/tests/test_http.py
index c1b21df..41a52f5 100644
--- a/src/python/lib/tests/test_http.py
+++ b/src/python/lib/tests/test_http.py
@@ -264,14 +264,12 @@ def test_resource_request_json(
def json_side_effect(_):
if json_exception is None:
return {'some': 'return_value'}
- else:
- raise json_exception
+ raise json_exception
def request_side_effect(*_, **__):
if request_exception is None:
return mock.Mock(status_code=resp_status)
- else:
- raise request_exception
+ raise request_exception
mock_mesos_http_request.side_effect = request_side_effect
mock_ujson_loads.side_effect = json_side_effect
diff --git a/support/apply-reviews.py b/support/apply-reviews.py
index 4e292a9..de22b70 100755
--- a/support/apply-reviews.py
+++ b/support/apply-reviews.py
@@ -101,6 +101,7 @@ def extract_review_id(url):
review_id = re.search(REVIEWBOARD_API_URL + r'/(\d+)/', url)
if review_id:
return review_id.group(1)
+ return None
def review_chain(review_id):
@@ -121,7 +122,7 @@ def review_chain(review_id):
sys.stderr.write('Error: Review {review} has more than'
' one parent'.format(review=review_id))
sys.exit(1)
- elif len(parent) == 0:
+ elif not parent:
return [(review_id, json_obj.get('review_request').get('summary'))]
else:
# The review has exactly one parent.
@@ -303,8 +304,7 @@ def patch_data(options):
return reviewboard_data(options)
elif options['github']:
return github_data(options)
- else:
- return None
+ return None
def get_author(patch):
diff --git a/support/generate-endpoint-help.py b/support/generate-endpoint-help.py
index 37c4b58..8b38f73 100755
--- a/support/generate-endpoint-help.py
+++ b/support/generate-endpoint-help.py
@@ -214,8 +214,7 @@ def get_relative_md_path(p_id, name):
if new_name:
return os.path.join(new_id, new_name + '.md')
- else:
- return os.path.join(new_id + '.md')
+ return os.path.join(new_id + '.md')
def write_markdown(path, output, title):
diff --git a/support/python3/apply-reviews.py b/support/python3/apply-reviews.py
index 6e1d6d7..92ad859 100755
--- a/support/python3/apply-reviews.py
+++ b/support/python3/apply-reviews.py
@@ -85,7 +85,7 @@ def patch_url(options):
return '{base}/{review}/diff/raw/'.format(
base=REVIEWBOARD_REVIEW_URL,
review=options['review_id'])
- elif options['github']:
+ if options['github']:
return '{base}/{patch}.patch'.format(
base=GITHUB_PATCH_URL,
patch=options['github'])
@@ -132,10 +132,9 @@ def review_chain(review_id):
review = (review_id, json_obj.get('review_request').get('summary'))
if review not in review_list:
return review_list + [review]
- else:
- sys.stderr.write('Found a circular dependency in the chain starting'
- ' at {review}\n'.format(review=review_id))
- sys.exit(1)
+ sys.stderr.write('Found a circular dependency in the chain starting'
+ ' at {review}\n'.format(review=review_id))
+ sys.exit(1)
def shell(command, dry_run):
@@ -303,7 +302,7 @@ def patch_data(options):
"""
if options['review_id']:
return reviewboard_data(options)
- elif options['github']:
+ if options['github']:
return github_data(options)
return None
diff --git a/support/python3/common.py b/support/python3/common.py
index ed62c67..845a687 100644
--- a/support/python3/common.py
+++ b/support/python3/common.py
@@ -35,7 +35,7 @@ class ReviewError(Exception):
pass
-class ReviewBoardHandler(object):
+class ReviewBoardHandler():
"""Handler class for ReviewBoard API operations."""
def __init__(self, user=None, password=None):
diff --git a/support/python3/generate-endpoint-help.py b/support/python3/generate-endpoint-help.py
index 6214d2e..2db9e14 100755
--- a/support/python3/generate-endpoint-help.py
+++ b/support/python3/generate-endpoint-help.py
@@ -81,7 +81,7 @@ RECEIVE_TIMEOUT = 10
RETRY_INTERVAL = 0.10
-class Subprocess(object):
+class Subprocess():
"""The process running using this script."""
def __init__(self):
self.current = None
diff --git a/support/python3/mesos-style.py b/support/python3/mesos-style.py
index 845ec73..c201038 100755
--- a/support/python3/mesos-style.py
+++ b/support/python3/mesos-style.py
@@ -25,8 +25,10 @@ import string
import subprocess
import sys
+from pathlib import PurePath
-class LinterBase(object):
+
+class LinterBase():
"""
This is an abstract class that provides the base functionality for
linting files in the mesos project. Its 'main()' function
@@ -152,7 +154,7 @@ class LinterBase(object):
virtualenv = os.path.join('support', '.virtualenv')
if platform.system() == 'Windows':
- command = '{virtualenv_path}\Scripts\activate.bat & {cmd}'.format(
+ command = r'{virtualenv_path}\Scripts\activate.bat & {cmd}'.format(
virtualenv_path=virtualenv, cmd=command)
else:
command = '. {virtualenv_path}/bin/activate; {cmd}'.format(
@@ -160,6 +162,7 @@ class LinterBase(object):
return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
+ # pylint: disable=unused-argument
def run_lint(self, source_paths):
"""
A custom function to provide linting for 'linter_type'.
@@ -169,7 +172,7 @@ class LinterBase(object):
It should print any errors as it encounters them to provide
feedback to the caller.
"""
- pass
+ return 0
def main(self, modified_files):
"""
@@ -192,8 +195,8 @@ class LinterBase(object):
for candidate in self.find_candidates(source_dir):
candidates.append(candidate)
- # Normalize paths of any files give.
- modified_files = map(os.path.normpath, modified_files)
+ # Normalize paths of any files given.
+ modified_files = [os.fspath(PurePath(f)) for f in modified_files]
# If file paths are specified, check all file paths that are
# candidates; else check all candidates.
@@ -439,7 +442,7 @@ class PyLinter(LinterBase):
num_errors = 0
for line in process.stdout:
line = line.decode(sys.stdout.encoding)
- if re.match(r'^[RCWEF]: *[\d]+', line):
+ if re.search(r'[RCWEF][0-9]{4}:', line):
num_errors += 1
sys.stderr.write(line)
@@ -519,16 +522,18 @@ def build_virtualenv():
python3_env = os.environ.copy()
python3_env["PYTHON"] = sys.executable
- build_virtualenv = [os.path.join('support', 'build-virtualenv')]
+ build_virtualenv_file = [os.path.join('support', 'build-virtualenv')]
if platform.system() == 'Windows':
# TODO(andschwa): Port more of the `build-virtualenv` Bash script.
python_dir = os.path.dirname(sys.executable)
virtualenv = os.path.join(python_dir, 'Scripts', 'virtualenv.exe')
- build_virtualenv = [virtualenv, '--no-site-packages', 'support/.virtualenv']
+ build_virtualenv_file = [virtualenv,
+ '--no-site-packages',
+ 'support/.virtualenv']
process = subprocess.Popen(
- build_virtualenv,
+ build_virtualenv_file,
env=python3_env,
stdout=subprocess.PIPE)
@@ -548,13 +553,17 @@ def build_virtualenv():
"""
Stolen from `PyLinter`, runs command in virtualenv.
"""
- virtualenv = os.path.join('support', '.virtualenv', 'Scripts', 'activate.bat')
+ virtualenv = os.path.join('support',
+ '.virtualenv',
+ 'Scripts',
+ 'activate.bat')
command = '{virtualenv_path} & {cmd}'.format(
virtualenv_path=virtualenv, cmd=command)
return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
- process = run_command_in_virtualenv('python.exe -m pip install --upgrade pip')
+ pip_install_pip = 'python.exe -m pip install --upgrade pip'
+ process = run_command_in_virtualenv(pip_install_pip)
for line in process.stdout:
output += line.decode(sys.stdout.encoding)
process.wait()
@@ -563,7 +572,8 @@ def build_virtualenv():
sys.stderr.write(output)
sys.exit(1)
- process = run_command_in_virtualenv('python.exe -m pip install -r support/pip-requirements.txt')
+ pip_reqs = 'python.exe -m pip install -r support/pip-requirements.txt'
+ process = run_command_in_virtualenv(pip_reqs)
for line in process.stdout:
output += line.decode(sys.stdout.encoding)
process.wait()
diff --git a/support/python3/push-commits.py b/support/python3/push-commits.py
index 7d88350..7be67e3 100755
--- a/support/python3/push-commits.py
+++ b/support/python3/push-commits.py
@@ -44,23 +44,23 @@ from subprocess import check_output
REVIEWBOARD_URL = 'https://reviews.apache.org'
def _check_output(args):
- return check_output(args).decode(sys.stdout.encoding)
+ return check_output(args).decode(sys.stdout.encoding)
def get_reviews(revision_range):
"""Return the list of reviews found in the commits in the revision range."""
reviews = [] # List of (review id, commit log) tuples
rev_list = _check_output(['git',
- 'rev-list',
- '--reverse',
- revision_range]).strip().split('\n')
+ 'rev-list',
+ '--reverse',
+ revision_range]).strip().split('\n')
for rev in rev_list:
commit_log = _check_output(['git',
- '--no-pager',
- 'show',
- '--no-color',
- '--no-patch',
- rev]).strip()
+ '--no-pager',
+ 'show',
+ '--no-color',
+ '--no-patch',
+ rev]).strip()
pos = commit_log.find('Review: ')
if pos != -1:
@@ -89,10 +89,10 @@ def close_reviews(reviews, options):
if platform.system() == 'Windows':
rbt_command = 'rbt.cmd'
_check_output([rbt_command,
- 'close',
- '--description',
- commit_log,
- review_id])
+ 'close',
+ '--description',
+ commit_log,
+ review_id])
def parse_options():
@@ -124,9 +124,9 @@ def main():
sys.exit(1)
remote_tracking_branch = _check_output(['git',
- 'rev-parse',
- '--abbrev-ref',
- 'master@{upstream}']).strip()
+ 'rev-parse',
+ '--abbrev-ref',
+ 'master@{upstream}']).strip()
merge_base = _check_output([
'git',
@@ -142,23 +142,23 @@ def main():
# Push the current branch to remote master.
remote = _check_output(['git',
- 'config',
- '--get',
- 'branch.master.remote']).strip()
+ 'config',
+ '--get',
+ 'branch.master.remote']).strip()
print('Pushing commits to', remote)
if options['dry_run']:
_check_output(['git',
- 'push',
- '--dry-run',
- remote,
- 'master:master'])
+ 'push',
+ '--dry-run',
+ remote,
+ 'master:master'])
else:
_check_output(['git',
- 'push',
- remote,
- 'master:master'])
+ 'push',
+ remote,
+ 'master:master'])
# Now mark the reviews as submitted.
close_reviews(reviews, options)
diff --git a/support/python3/test-upgrade.py b/support/python3/test-upgrade.py
index a1745bd..3a7bcac 100755
--- a/support/python3/test-upgrade.py
+++ b/support/python3/test-upgrade.py
@@ -29,7 +29,7 @@ DEFAULT_PRINCIPAL = 'foo'
DEFAULT_SECRET = 'bar'
-class Process(object):
+class Process():
"""
Helper class to keep track of process lifecycles.
@@ -62,7 +62,7 @@ class Process(object):
seconds -= poll_time
time.sleep(poll_time)
poll = self.process.poll()
- if poll != None:
+ if poll is not None:
return poll
return True
diff --git a/support/verify-reviews.py b/support/verify-reviews.py
index c86db35..3d8c67e 100755
--- a/support/verify-reviews.py
+++ b/support/verify-reviews.py
@@ -258,7 +258,7 @@ def needs_verification(review_request):
diffs_url = review_request["links"]["diffs"]["href"]
diffs = api(diffs_url)
- if len(diffs["diffs"]) == 0: # No diffs attached!
+ if not diffs["diffs"]: # No diffs attached!
print "Skipping review %s as it has no diffs" % review_request["id"]
return False