Update pylintrc to a pep-8 like style

In particular, this requires reformatting
- autoroller/
- PRESUBMIT.py
- infra/config/PRESUBMIT.py
- get_landmines.py
- download_vs_toolchain.py
as well as some manual fixes.

This CL is preparation to updating the autoroller so that we can roll DEPS from chromium.

No-Try: True
Bug: libyuv:358992053
Change-Id: I090a09c6fa61beff2427a0537bca371f0839fa3e
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/6105550
Reviewed-by: Mirko Bonadei <mbonadei@chromium.org>
Reviewed-by: Jeremy Leconte <jleconte@google.com>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
This commit is contained in:
Björn Terelius 2024-12-18 14:02:45 +01:00 committed by libyuv LUCI CQ
parent 2c682f8d59
commit 37e88ecc68
7 changed files with 792 additions and 635 deletions

View File

@ -9,44 +9,57 @@
# Runs PRESUBMIT.py in py3 mode by git cl presubmit. # Runs PRESUBMIT.py in py3 mode by git cl presubmit.
USE_PYTHON3 = True USE_PYTHON3 = True
def _CommonChecks(input_api, output_api): def _CommonChecks(input_api, output_api):
"""Checks common to both upload and commit.""" """Checks common to both upload and commit."""
results = [] results = []
results.extend(input_api.canned_checks.RunPylint(input_api, output_api, results.extend(
files_to_skip=(r'^base[\\\/].*\.py$', input_api.canned_checks.RunPylint(
r'^build[\\\/].*\.py$', input_api,
r'^buildtools[\\\/].*\.py$', output_api,
r'^ios[\\\/].*\.py$', files_to_skip=(
r'^out.*[\\\/].*\.py$', r'^base[\\\/].*\.py$',
r'^testing[\\\/].*\.py$', r'^build[\\\/].*\.py$',
r'^third_party[\\\/].*\.py$', r'^buildtools[\\\/].*\.py$',
r'^tools[\\\/].*\.py$', r'^ios[\\\/].*\.py$',
# TODO(kjellander): should arguably be checked. r'^out.*[\\\/].*\.py$',
r'^tools_libyuv[\\\/]valgrind[\\\/].*\.py$', r'^testing[\\\/].*\.py$',
r'^xcodebuild.*[\\\/].*\.py$',), r'^third_party[\\\/].*\.py$',
disabled_warnings=['F0401', # Failed to import x r'^tools[\\\/].*\.py$',
'E0611', # No package y in x # TODO(kjellander): should arguably be checked.
'W0232', # Class has no __init__ method r'^tools_libyuv[\\\/]valgrind[\\\/].*\.py$',
], r'^xcodebuild.*[\\\/].*\.py$',
pylintrc='pylintrc', ),
version='2.7')) disabled_warnings=[
return results 'F0401', # Failed to import x
'E0611', # No package y in x
'W0232', # Class has no __init__ method
],
pylintrc='pylintrc',
version='2.7',
)
)
return results
def CheckChangeOnUpload(input_api, output_api): def CheckChangeOnUpload(input_api, output_api):
results = [] results = []
results.extend(_CommonChecks(input_api, output_api)) results.extend(_CommonChecks(input_api, output_api))
results.extend( results.extend(
input_api.canned_checks.CheckGNFormatted(input_api, output_api)) input_api.canned_checks.CheckGNFormatted(input_api, output_api)
return results )
return results
def CheckChangeOnCommit(input_api, output_api): def CheckChangeOnCommit(input_api, output_api):
results = [] results = []
results.extend(_CommonChecks(input_api, output_api)) results.extend(_CommonChecks(input_api, output_api))
results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeWasUploaded( results.extend(
input_api, output_api)) input_api.canned_checks.CheckChangeWasUploaded(input_api, output_api)
results.extend(input_api.canned_checks.CheckChangeHasDescription( )
input_api, output_api)) results.extend(
return results input_api.canned_checks.CheckChangeHasDescription(input_api,
output_api)
)
return results

View File

@ -26,4 +26,4 @@ import vs_toolchain # pylint: disable=wrong-import-position
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(vs_toolchain.main()) sys.exit(vs_toolchain.main())

View File

@ -6,8 +6,12 @@ USE_PYTHON3 = True
def CheckChangeOnUpload(input_api, output_api): def CheckChangeOnUpload(input_api, output_api):
return input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api) return input_api.canned_checks.CheckChangedLUCIConfigs(
input_api, output_api
)
def CheckChangeOnCommit(input_api, output_api): def CheckChangeOnCommit(input_api, output_api):
return input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api) return input_api.canned_checks.CheckChangedLUCIConfigs(
input_api, output_api
)

View File

@ -13,5 +13,37 @@ reports=no
[FORMAT] [FORMAT]
# We use two spaces for indents, instead of the usual four spaces or tab. # Maximum number of characters on a single line.
indent-string=' ' max-line-length=79
# We use four spaces for indents.
indent-string=' '
[BASIC]
# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter,apply,input
# Naming style matching correct module names.
module-naming-style=snake_case
# Naming style matching correct constant names.
const-naming-style=UPPER_CASE
# Naming style matching correct class names.
class-naming-style=PascalCase
# Naming style matching correct function names.
function-naming-style=snake_case
# Regular expression matching correct method names.
method-rgx=([a-z_][a-z0-9_]{2,}|setUp|tearDown)$
# Naming style matching correct attribute names.
attr-naming-style=snake_case
# Naming style matching correct argument names.
argument-naming-style=snake_case
# Naming style matching correct variable names.
variable-naming-style=snake_case

File diff suppressed because it is too large Load Diff

View File

@ -16,23 +16,22 @@ import tempfile
import unittest import unittest
import roll_deps import roll_deps
from roll_deps import CalculateChangedDeps, GetMatchingDepsEntries, \ from roll_deps import CalculateChangedDeps, GetMatchingDepsEntries, ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile # pylint: disable=line-too-long
ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.join(SCRIPT_DIR, os.pardir) PARENT_DIR = os.path.join(SCRIPT_DIR, os.pardir)
sys.path.append(PARENT_DIR) sys.path.append(PARENT_DIR)
TEST_DATA_VARS = { TEST_DATA_VARS = {
'chromium_git': 'https://chromium.googlesource.com', 'chromium_git': 'https://chromium.googlesource.com',
'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d', 'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d',
} }
DEPS_ENTRIES = { DEPS_ENTRIES = {
'src/build': 'https://build.com', 'src/build': 'https://build.com',
'src/buildtools': 'https://buildtools.com', 'src/buildtools': 'https://buildtools.com',
'src/testing/gtest': 'https://gtest.com', 'src/testing/gtest': 'https://gtest.com',
'src/testing/gmock': 'https://gmock.com', 'src/testing/gmock': 'https://gmock.com',
} }
BUILD_OLD_REV = '52f7afeca991d96d68cf0507e20dbdd5b845691f' BUILD_OLD_REV = '52f7afeca991d96d68cf0507e20dbdd5b845691f'
@ -42,107 +41,124 @@ BUILDTOOLS_NEW_REV = '55ad626b08ef971fd82a62b7abb325359542952b'
class TestError(Exception): class TestError(Exception):
pass pass
class FakeCmd(): class FakeCmd:
def __init__(self):
self.expectations = []
def add_expectation(self, *args, **kwargs): def __init__(self):
returns = kwargs.pop('_returns', None) self.expectations = []
self.expectations.append((args, kwargs, returns))
def __call__(self, *args, **kwargs): def add_expectation(self, *args, **kwargs):
if not self.expectations: returns = kwargs.pop('_returns', None)
raise TestError('Got unexpected\n%s\n%s' % (args, kwargs)) self.expectations.append((args, kwargs, returns))
exp_args, exp_kwargs, exp_returns = self.expectations.pop(0)
if args != exp_args or kwargs != exp_kwargs: def __call__(self, *args, **kwargs):
message = 'Expected:\n args: %s\n kwargs: %s\n' % (exp_args, exp_kwargs) if not self.expectations:
message += 'Got:\n args: %s\n kwargs: %s\n' % (args, kwargs) raise TestError('Got unexpected\n%s\n%s' % (args, kwargs))
raise TestError(message) exp_args, exp_kwargs, exp_returns = self.expectations.pop(0)
return exp_returns if args != exp_args or kwargs != exp_kwargs:
message = 'Expected:\n args: %s\n kwargs: %s\n' % (
exp_args,
exp_kwargs,
)
message += 'Got:\n args: %s\n kwargs: %s\n' % (args, kwargs)
raise TestError(message)
return exp_returns
class TestRollChromiumRevision(unittest.TestCase): class TestRollChromiumRevision(unittest.TestCase):
def setUp(self):
self._output_dir = tempfile.mkdtemp()
for test_file in glob.glob(os.path.join(SCRIPT_DIR, 'testdata', '*')):
shutil.copy(test_file, self._output_dir)
self._libyuv_depsfile = os.path.join(self._output_dir, 'DEPS')
self._old_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.old')
self._new_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.new')
self.fake = FakeCmd() def setUp(self):
self.old_RunCommand = getattr(roll_deps, '_RunCommand') self._output_dir = tempfile.mkdtemp()
setattr(roll_deps, '_RunCommand', self.fake) for test_file in glob.glob(os.path.join(SCRIPT_DIR, 'testdata', '*')):
shutil.copy(test_file, self._output_dir)
self._libyuv_depsfile = os.path.join(self._output_dir, 'DEPS')
self._old_cr_depsfile = os.path.join(
self._output_dir, 'DEPS.chromium.old'
)
self._new_cr_depsfile = os.path.join(
self._output_dir, 'DEPS.chromium.new'
)
def tearDown(self): self.fake = FakeCmd()
shutil.rmtree(self._output_dir, ignore_errors=True) self.old_RunCommand = getattr(roll_deps, '_RunCommand')
self.assertEqual(self.fake.expectations, []) setattr(roll_deps, '_RunCommand', self.fake)
setattr(roll_deps, '_RunCommand', self.old_RunCommand)
def testVarLookup(self): def tearDown(self):
local_scope = {'foo': 'wrong', 'vars': {'foo': 'bar'}} shutil.rmtree(self._output_dir, ignore_errors=True)
lookup = roll_deps.VarLookup(local_scope) self.assertEqual(self.fake.expectations, [])
self.assertEqual(lookup('foo'), 'bar') setattr(roll_deps, '_RunCommand', self.old_RunCommand)
def testUpdateDepsFile(self): def testVarLookup(self):
new_rev = 'aaaaabbbbbcccccdddddeeeeefffff0000011111' local_scope = {'foo': 'wrong', 'vars': {'foo': 'bar'}}
lookup = roll_deps.VarLookup(local_scope)
self.assertEqual(lookup('foo'), 'bar')
current_rev = TEST_DATA_VARS['chromium_revision'] def testUpdateDepsFile(self):
UpdateDepsFile(self._libyuv_depsfile, current_rev, new_rev, []) new_rev = 'aaaaabbbbbcccccdddddeeeeefffff0000011111'
with open(self._libyuv_depsfile, 'r') as deps_file:
deps_contents = deps_file.read()
self.assertTrue(new_rev in deps_contents,
'Failed to find %s in\n%s' % (new_rev, deps_contents))
def testParseDepsDict(self): current_rev = TEST_DATA_VARS['chromium_revision']
with open(self._libyuv_depsfile, 'r') as deps_file: UpdateDepsFile(self._libyuv_depsfile, current_rev, new_rev, [])
deps_contents = deps_file.read() with open(self._libyuv_depsfile, 'r') as deps_file:
local_scope = ParseDepsDict(deps_contents) deps_contents = deps_file.read()
vars_dict = local_scope['vars'] self.assertTrue(
new_rev in deps_contents,
'Failed to find %s in\n%s' % (new_rev, deps_contents),
)
def assertVar(variable_name): def testParseDepsDict(self):
self.assertEqual(vars_dict[variable_name], TEST_DATA_VARS[variable_name]) with open(self._libyuv_depsfile, 'r') as deps_file:
assertVar('chromium_git') deps_contents = deps_file.read()
assertVar('chromium_revision') local_scope = ParseDepsDict(deps_contents)
self.assertEqual(len(local_scope['deps']), 3) vars_dict = local_scope['vars']
def testGetMatchingDepsEntriesReturnsPathInSimpleCase(self): def assertVar(variable_name):
entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing/gtest') self.assertEqual(
self.assertEqual(len(entries), 1) vars_dict[variable_name], TEST_DATA_VARS[variable_name]
self.assertEqual(entries[0], DEPS_ENTRIES['src/testing/gtest']) )
def testGetMatchingDepsEntriesHandlesSimilarStartingPaths(self): assertVar('chromium_git')
entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing') assertVar('chromium_revision')
self.assertEqual(len(entries), 2) self.assertEqual(len(local_scope['deps']), 3)
def testGetMatchingDepsEntriesHandlesTwoPathsWithIdenticalFirstParts(self): def testGetMatchingDepsEntriesReturnsPathInSimpleCase(self):
entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/build') entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing/gtest')
self.assertEqual(len(entries), 1) self.assertEqual(len(entries), 1)
self.assertEqual(entries[0], DEPS_ENTRIES['src/build']) self.assertEqual(entries[0], DEPS_ENTRIES['src/testing/gtest'])
def testCalculateChangedDeps(self): def testGetMatchingDepsEntriesHandlesSimilarStartingPaths(self):
_SetupGitLsRemoteCall(self.fake, entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing')
'https://chromium.googlesource.com/chromium/src/build', BUILD_NEW_REV) self.assertEqual(len(entries), 2)
libyuv_deps = ParseLocalDepsFile(self._libyuv_depsfile)
new_cr_deps = ParseLocalDepsFile(self._new_cr_depsfile)
changed_deps = CalculateChangedDeps(libyuv_deps, new_cr_deps)
self.assertEqual(len(changed_deps), 2)
self.assertEqual(changed_deps[0].path, 'src/build')
self.assertEqual(changed_deps[0].current_rev, BUILD_OLD_REV)
self.assertEqual(changed_deps[0].new_rev, BUILD_NEW_REV)
self.assertEqual(changed_deps[1].path, 'src/buildtools') def testGetMatchingDepsEntriesHandlesTwoPathsWithIdenticalFirstParts(self):
self.assertEqual(changed_deps[1].current_rev, BUILDTOOLS_OLD_REV) entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/build')
self.assertEqual(changed_deps[1].new_rev, BUILDTOOLS_NEW_REV) self.assertEqual(len(entries), 1)
self.assertEqual(entries[0], DEPS_ENTRIES['src/build'])
def testCalculateChangedDeps(self):
_SetupGitLsRemoteCall(
self.fake,
'https://chromium.googlesource.com/chromium/src/build',
BUILD_NEW_REV,
)
libyuv_deps = ParseLocalDepsFile(self._libyuv_depsfile)
new_cr_deps = ParseLocalDepsFile(self._new_cr_depsfile)
changed_deps = CalculateChangedDeps(libyuv_deps, new_cr_deps)
self.assertEqual(len(changed_deps), 2)
self.assertEqual(changed_deps[0].path, 'src/build')
self.assertEqual(changed_deps[0].current_rev, BUILD_OLD_REV)
self.assertEqual(changed_deps[0].new_rev, BUILD_NEW_REV)
self.assertEqual(changed_deps[1].path, 'src/buildtools')
self.assertEqual(changed_deps[1].current_rev, BUILDTOOLS_OLD_REV)
self.assertEqual(changed_deps[1].new_rev, BUILDTOOLS_NEW_REV)
def _SetupGitLsRemoteCall(cmd_fake, url, revision): def _SetupGitLsRemoteCall(cmd_fake, url, revision):
cmd = ['git', 'ls-remote', url, revision] cmd = ['git', 'ls-remote', url, revision]
cmd_fake.add_expectation(cmd, _returns=(revision, None)) cmd_fake.add_expectation(cmd, _returns=(revision, None))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -9,31 +9,30 @@
# be found in the AUTHORS file in the root of the source tree. # be found in the AUTHORS file in the root of the source tree.
""" """
This file emits the list of reasons why a particular build needs to be clobbered This file emits the list of reasons why a particular build needs to be
(or a list of 'landmines'). clobbered (or a list of 'landmines').
""" """
import sys import sys
def print_landmines(): def print_landmines():
""" """ALL LANDMINES ARE EMITTED FROM HERE."""
ALL LANDMINES ARE EMITTED FROM HERE. # DO NOT add landmines as part of a regular CL. Landmines are a last-effort
""" # bandaid fix if a CL that got landed has a build dependency bug and all
# DO NOT add landmines as part of a regular CL. Landmines are a last-effort # bots need to be cleaned up. If you're writing a new CL that causes build
# bandaid fix if a CL that got landed has a build dependency bug and all bots # dependency problems, fix the dependency problems instead of adding a
# need to be cleaned up. If you're writing a new CL that causes build # landmine.
# dependency problems, fix the dependency problems instead of adding a # See the Chromium version in src/build/get_landmines.py for usage
# landmine. # examples.
# See the Chromium version in src/build/get_landmines.py for usage examples. print('Clobber to remove GYP artifacts after switching bots to GN.')
print('Clobber to remove GYP artifacts after switching bots to GN.') print('Another try to remove GYP artifacts after switching bots to GN.')
print('Another try to remove GYP artifacts after switching bots to GN.')
def main(): def main():
print_landmines() print_landmines()
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())