Use pylint3 hook
The repohook configuration currently tries to force the use of a
specific executable name for pylint3. Let repohook find the most
appropriate executable by using the pylint3 hook instead.
Fix the current warnings raised.
Test: repo upload .
Change-Id: I653aa921bbc8d2aec350b827c6828c1b761821e9
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index f52b2bd..9e97695 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -1,5 +1,2 @@
[Builtin Hooks]
-pylint = true
-
-[Builtin Hooks Options]
-pylint = --executable-path pylint3 ${PREUPLOAD_FILES}
+pylint3 = true
diff --git a/base_updater.py b/base_updater.py
index 74b688d..d053054 100644
--- a/base_updater.py
+++ b/base_updater.py
@@ -16,6 +16,7 @@
from pathlib import Path
import fileutils
+# pylint: disable=import-error
import metadata_pb2 # type: ignore
diff --git a/crates_updater.py b/crates_updater.py
index 684f15f..b8e48d3 100644
--- a/crates_updater.py
+++ b/crates_updater.py
@@ -19,6 +19,7 @@
import archive_utils
from base_updater import Updater
+# pylint: disable=import-error
import metadata_pb2 # type: ignore
import updater_utils
@@ -107,6 +108,7 @@
finally:
urllib.request.urlcleanup()
+ # pylint: disable=no-self-use
def update_metadata(self, metadata: metadata_pb2.MetaData) -> None:
"""Updates METADATA content."""
# copy only HOMEPAGE url, and then add new ARCHIVE url.
diff --git a/external_updater.py b/external_updater.py
index 98de039..ce0bb3c 100644
--- a/external_updater.py
+++ b/external_updater.py
@@ -35,6 +35,7 @@
from github_archive_updater import GithubArchiveUpdater
import fileutils
import git_utils
+# pylint: disable=import-error
import metadata_pb2 # type: ignore
import updater_utils
@@ -156,6 +157,7 @@
if update_lib and (has_new_version or args.force):
_do_update(args, updater, metadata)
return updater
+ # pylint: disable=broad-except
except Exception as err:
print('{} {}.'.format(color_string('Failed.', Color.ERROR), err))
return str(err)
diff --git a/external_updater_reviewers_test.py b/external_updater_reviewers_test.py
index e055296..f9c2014 100644
--- a/external_updater_reviewers_test.py
+++ b/external_updater_reviewers_test.py
@@ -40,6 +40,7 @@
reviewers.NUM_RUST_PROJECTS = self.saved_num_rust_projects
reviewers.RUST_CRATE_OWNERS = self.saved_rust_crate_owners
+ # pylint: disable=no-self-use
def _collect_reviewers(self, num_runs, proj_path):
counters = {}
for _ in range(num_runs):
@@ -51,21 +52,26 @@
return counters
def test_reviewers_types(self):
+ """Check the types of PROJ_REVIEWERS and RUST_REVIEWERS."""
# Check type of PROJ_REVIEWERS
self.assertIsInstance(reviewers.PROJ_REVIEWERS, Mapping)
for key, value in reviewers.PROJ_REVIEWERS.items():
self.assertIsInstance(key, str)
- if isinstance(value, Set) or isinstance(value, List):
- map(lambda x: self.assertIsInstance(x, str), value)
+ # pylint: disable=isinstance-second-argument-not-valid-type
+ # https://github.com/PyCQA/pylint/issues/3507
+ if isinstance(value, (List, Set)):
+ for x in value:
+ self.assertIsInstance(x, str)
else:
self.assertIsInstance(value, str)
# Check element types of the reviewers list and map.
self.assertIsInstance(reviewers.RUST_REVIEWERS, Mapping)
- for (x, n) in reviewers.RUST_REVIEWERS.items():
- self.assertIsInstance(x, str)
- self.assertIsInstance(n, int)
+ for (name, quota) in reviewers.RUST_REVIEWERS.items():
+ self.assertIsInstance(name, str)
+ self.assertIsInstance(quota, int)
def test_reviewers_constants(self):
+ """Check the constants associated to the reviewers."""
# There should be enough people in the reviewers pool.
self.assertGreaterEqual(len(reviewers.RUST_REVIEWERS), 3)
# The NUM_RUST_PROJECTS should not be too small.
@@ -84,7 +90,7 @@
self.assertGreaterEqual(sum_projects, reviewers.NUM_RUST_PROJECTS)
def test_reviewers_randomness(self):
- # Check random selection of reviewers.
+ """Check random selection of reviewers."""
# This might fail when the random.choice function is extremely unfair.
# With N * 20 tries, each reviewer should be picked at least twice.
# Assume no project reviewers and recreate RUST_REVIEWER_LIST
@@ -93,11 +99,12 @@
num_tries = len(reviewers.RUST_REVIEWERS) * 20
counters = self._collect_reviewers(num_tries, "rust/crates/libc")
self.assertEqual(len(counters), len(reviewers.RUST_REVIEWERS))
- map(lambda n: self.assertGreaterEqual(n, 10), counters.values())
+ for n in counters.values():
+ self.assertGreaterEqual(n, 10)
self.assertEqual(sum(counters.values()), num_tries)
def test_project_reviewers(self):
- # For specific projects, select only the specified reviewers.
+ """For specific projects, select only the specified reviewers."""
reviewers.PROJ_REVIEWERS = {
"rust/crates/p1": "x@g.com",
"rust/crates/p_any": ["x@g.com", "y@g.com"],
@@ -116,7 +123,7 @@
self.assertEqual(counters["r=x@g.com,r=y@g.com,r=z@g"], 20)
def test_weighted_reviewers(self):
- # Test create_rust_reviewer_list
+ """Test create_rust_reviewer_list."""
reviewers.PROJ_REVIEWERS = {
"any_p1": "x@g", # 1 for x@g
"any_p2": {"xyz", "x@g"}, # 1 for x@g, xyz is not a rust reviewer
diff --git a/git_utils.py b/git_utils.py
index 8cc30fd..0304417 100644
--- a/git_utils.py
+++ b/git_utils.py
@@ -86,6 +86,7 @@
return out.splitlines()
+# pylint: disable=redefined-outer-name
def get_commit_time(proj_path: Path, commit: str) -> datetime.datetime:
"""Gets commit time of one commit."""
out = _run(['git', 'show', '-s', '--format=%ct', commit], cwd=proj_path)
@@ -119,6 +120,7 @@
COMMIT_RE = re.compile(COMMIT_PATTERN)
+# pylint: disable=redefined-outer-name
def is_commit(commit: str) -> bool:
"""Whether a string looks like a SHA1 hash."""
return bool(COMMIT_RE.match(commit))
diff --git a/github_archive_updater.py b/github_archive_updater.py
index cc3840f..fc3e362 100644
--- a/github_archive_updater.py
+++ b/github_archive_updater.py
@@ -23,6 +23,7 @@
import archive_utils
from base_updater import Updater
import git_utils
+# pylint: disable=import-error
import metadata_pb2 # type: ignore
import updater_utils
@@ -88,6 +89,7 @@
return True
def _fetch_latest_release(self) -> Optional[Tuple[str, List[str]]]:
+ # pylint: disable=line-too-long
url = f'https://api.github.com/repos/{self.owner}/{self.repo}/releases/latest'
try:
with urllib.request.urlopen(url) as request:
@@ -109,6 +111,7 @@
for page in range(1, 21):
# Sleeps 10s to avoid rate limit.
time.sleep(10)
+ # pylint: disable=line-too-long
url = f'https://api.github.com/repos/{self.owner}/{self.repo}/tags?page={page}'
with urllib.request.urlopen(url) as request:
data = json.loads(request.read().decode())
@@ -133,11 +136,13 @@
def _fetch_latest_commit(self) -> None:
"""Checks upstream and gets the latest commit to master."""
+ # pylint: disable=line-too-long
url = f'https://api.github.com/repos/{self.owner}/{self.repo}/commits/master'
with urllib.request.urlopen(url) as request:
data = json.loads(request.read().decode())
self._new_ver = data['sha']
self._new_url.value = (
+ # pylint: disable=line-too-long
f'https://github.com/{self.owner}/{self.repo}/archive/{self._new_ver}.zip'
)
diff --git a/hashtags.py b/hashtags.py
index a76b4bf..9b043dd 100644
--- a/hashtags.py
+++ b/hashtags.py
@@ -20,4 +20,3 @@
if str(proj_path).find('/external/rust/') != -1:
return 'external_updater_rust'
return 'external_updater'
-
diff --git a/notifier.py b/notifier.py
index 97ca2bd..7e2e4c7 100644
--- a/notifier.py
+++ b/notifier.py
@@ -29,6 +29,7 @@
import subprocess
import time
+# pylint: disable=invalid-name
def parse_args():
"""Parses commandline arguments."""
@@ -163,6 +164,7 @@
def _upgrade(proj):
+ # pylint: disable=subprocess-run-check
out = subprocess.run([
'out/soong/host/linux-x86/bin/external_updater', 'update',
'--branch_and_commit', '--push_change', proj
@@ -195,6 +197,7 @@
params += args.paths
print(_get_android_top())
+ # pylint: disable=subprocess-run-check
subprocess.run(params, cwd=_get_android_top())
diff --git a/reviewers.py b/reviewers.py
index 8b366c2..c6f48d6 100644
--- a/reviewers.py
+++ b/reviewers.py
@@ -101,6 +101,7 @@
}
+# pylint: disable=invalid-name
def add_proj_count(projects: Mapping[str, float], reviewer: str, n: float):
"""Add n to the number of projects owned by the reviewer."""
if reviewer in projects:
@@ -124,6 +125,7 @@
add_proj_count(projects, value, 1)
continue
# multiple reviewers share one project, count only rust_reviewers
+ # pylint: disable=bad-builtin
reviewers = set(filter(lambda x: x in rust_reviewers, value))
if reviewers:
count = 1.0 / len(reviewers) # shared among all reviewers
@@ -154,9 +156,11 @@
proj_path = proj_path[len('external/'):]
if proj_path in PROJ_REVIEWERS:
reviewers = PROJ_REVIEWERS[proj_path]
+ # pylint: disable=isinstance-second-argument-not-valid-type
if isinstance(reviewers, List): # pick any one reviewer
return 'r=' + random.choice(reviewers)
if isinstance(reviewers, Set): # add all reviewers in sorted order
+ # pylint: disable=bad-builtin
return ','.join(map(lambda x: 'r=' + x, sorted(reviewers)))
# reviewers must be a string
return 'r=' + reviewers
diff --git a/updater_utils.py b/updater_utils.py
index 3301e8f..1bcd567 100644
--- a/updater_utils.py
+++ b/updater_utils.py
@@ -21,6 +21,7 @@
from typing import List, Tuple, Type
from base_updater import Updater
+# pylint: disable=import-error
import metadata_pb2 # type: ignore
@@ -80,6 +81,7 @@
versions = [int(v) for v in VERSION_SPLITTER_RE.split(version)]
return (versions, str(prefix), str(suffix))
except IndexError:
+ # pylint: disable=raise-missing-from
raise ValueError('Invalid version.')