Skip to content

Commit

Permalink
Enable whitespace pylint checks.
Browse files Browse the repository at this point in the history
This CL makes whitespace formatting more consistent within the catapult
repo. This means:
 * 2-space indent (Chromium style)
 * 4-space indent for line continuations
 * 2 spaces before one-line comments
 * 1 space around binary operators (suggested by PEP8, not a strict rule)
 * 2 blank lines around top-level functions and classes
 * 1 blank line around methods in a class

Some of the changes were done automatically using:
Run autopep8 --select=E2,W2,E3 --indent-size=2 --max-line-length=80
Others were done manually.

BUG=catapult:catapult-project#1888

Review URL: https://codereview.chromium.org/1589553002
  • Loading branch information
qyearsley authored and Commit bot committed Jan 14, 2016
1 parent 1200798 commit 066bee6
Show file tree
Hide file tree
Showing 113 changed files with 586 additions and 389 deletions.
1 change: 1 addition & 0 deletions catapult_base/catapult_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from catapult_base import util


def _AddDirToPythonPath(*path_parts):
path = os.path.abspath(os.path.join(*path_parts))
if os.path.isdir(path) and path not in sys.path:
Expand Down
9 changes: 7 additions & 2 deletions catapult_base/catapult_base/cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
_CROS_GSUTIL_HOME_WAR = '/home/chromeos-test/'



class CloudStorageError(Exception):

@staticmethod
def _GetConfigInstructions():
command = _GSUTIL_PATH
Expand All @@ -63,13 +63,15 @@ def _GetConfigInstructions():


class PermissionError(CloudStorageError):

def __init__(self):
super(PermissionError, self).__init__(
'Attempted to access a file from Cloud Storage but you don\'t '
'have permission. ' + self._GetConfigInstructions())


class CredentialsError(CloudStorageError):

def __init__(self):
super(CredentialsError, self).__init__(
'Attempted to access a file from Cloud Storage but you have no '
Expand All @@ -93,12 +95,14 @@ def _FindExecutableInPath(relative_executable_path, *extra_search_paths):
return executable_path
return None


def _EnsureExecutable(gsutil):
"""chmod +x if gsutil is not executable."""
st = os.stat(gsutil)
if not st.st_mode & stat.S_IEXEC:
os.chmod(gsutil, st.st_mode | stat.S_IEXEC)


def _RunCommand(args):
# On cros device, as telemetry is running as root, home will be set to /root/,
# which is not writable. gsutil will attempt to create a download tracker dir
Expand Down Expand Up @@ -330,13 +334,14 @@ def GetFilesInDirectoryIfChanged(directory, bucket):
continue
GetIfChanged(path_name, bucket)


def CalculateHash(file_path):
"""Calculates and returns the hash of the file at file_path."""
sha1 = hashlib.sha1()
with open(file_path, 'rb') as f:
while True:
# Read in 1mb chunks, so it doesn't all have to be loaded into memory.
chunk = f.read(1024*1024)
chunk = f.read(1024 * 1024)
if not chunk:
break
sha1.update(chunk)
Expand Down
20 changes: 12 additions & 8 deletions catapult_base/catapult_base/cloud_storage_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
def _FakeReadHash(_):
return 'hashthis!'


def _FakeCalulateHashMatchesRead(_):
return 'hashthis!'


def _FakeCalulateHashNewHash(_):
return 'omgnewhash'

Expand Down Expand Up @@ -56,7 +58,7 @@ def _assertRunCommandRaisesError(self, communicate_strs, error):

def testRunCommandCredentialsError(self):
strs = ['You are attempting to access protected data with no configured',
'Failure: No handler was ready to authenticate.']
'Failure: No handler was ready to authenticate.']
self._assertRunCommandRaisesError(strs, cloud_storage.CredentialsError)

def testRunCommandPermissionError(self):
Expand Down Expand Up @@ -95,8 +97,8 @@ def testExistsReturnsFalse(self, subprocess_mock):
p_mock = mock.Mock()
subprocess_mock.Popen.return_value = p_mock
p_mock.communicate.return_value = (
'',
'CommandException: One or more URLs matched no objects.\n')
'',
'CommandException: One or more URLs matched no objects.\n')
p_mock.returncode_result = 1
self.assertFalse(cloud_storage.Exists('fake bucket',
'fake remote path'))
Expand Down Expand Up @@ -172,11 +174,12 @@ def testGetIfChanged(self, lock_mock):
'https://github.com/catapult-project/catapult/issues/1861')
def testGetFilesInDirectoryIfChanged(self):
self.CreateFiles([
'real_dir_path/dir1/1file1.sha1',
'real_dir_path/dir1/1file2.txt',
'real_dir_path/dir1/1file3.sha1',
'real_dir_path/dir2/2file.txt',
'real_dir_path/dir3/3file1.sha1'])
'real_dir_path/dir1/1file1.sha1',
'real_dir_path/dir1/1file2.txt',
'real_dir_path/dir1/1file3.sha1',
'real_dir_path/dir2/2file.txt',
'real_dir_path/dir3/3file1.sha1'])

def IncrementFilesUpdated(*_):
IncrementFilesUpdated.files_updated += 1
IncrementFilesUpdated.files_updated = 0
Expand All @@ -197,6 +200,7 @@ def IncrementFilesUpdated(*_):

def testCopy(self):
orig_run_command = cloud_storage._RunCommand

def AssertCorrectRunCommandArgs(args):
self.assertEqual(expected_args, args)
cloud_storage._RunCommand = AssertCorrectRunCommandArgs
Expand Down
1 change: 0 additions & 1 deletion catapult_base/catapult_base/perfbot_stats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main():
days = range(1, calendar.monthrange(year, month)[1] + 1)
else:
day = int(sys.argv[3])
if day > 31 or day <=0:
if day > 31 or day <= 0:
print USAGE
sys.exit(0)
days = [day]
Expand Down Expand Up @@ -84,6 +84,7 @@ def _UpdateSuccessRatesWithResult(
success_rates[date_dict_str][builder]['count'] += count
success_rates[date_dict_str][builder]['success_count'] += success_count


def _SummarizeSuccessRates(success_rates):
overall_success_rates = []
for day, results in success_rates.iteritems():
Expand All @@ -102,8 +103,9 @@ def _SummarizeSuccessRates(success_rates):

def UploadToPerfDashboard(success_rates):
for success_rate in success_rates:
date_str = ('%s-%s-%s' %
(success_rate[0][0:4], success_rate[0][4:6], success_rate[0][6:8]))
date_str = '%s-%s-%s' % (success_rate[0][0:4],
success_rate[0][4:6],
success_rate[0][6:8])
dashboard_data = {
'master': 'WaterfallStats',
'bot': 'ChromiumPerf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,65 @@ def testUpdateSuccessRatesWithResult(self):
'invalid_builder')
self.assertDictEqual({}, success_rates)
chrome_perf_stats._UpdateSuccessRatesWithResult(
success_rates,
{'count': 5, 'failure_count': 3},
'20151010',
'android_nexus_10')
success_rates,
{'count': 5, 'failure_count': 3},
'20151010',
'android_nexus_10')
self.assertDictEqual(
{'20151010':
{'android_nexus_10':
{'count': 5, 'success_count': 2}
}
},
}
},
success_rates)
chrome_perf_stats._UpdateSuccessRatesWithResult(
success_rates,
{'count': 5, 'failure_count': 4},
'20151010',
'android_nexus_4')
success_rates,
{'count': 5, 'failure_count': 4},
'20151010',
'android_nexus_4')
self.assertDictEqual(
{'20151010':
{'android_nexus_10':
{'count': 5, 'success_count': 2},
'android_nexus_4':
{'count': 5, 'success_count': 1}
}
},
}
},
success_rates)
chrome_perf_stats._UpdateSuccessRatesWithResult(
success_rates,
{'count': 5, 'failure_count': 0},
'20151009',
'win_xp')
success_rates,
{'count': 5, 'failure_count': 0},
'20151009',
'win_xp')
self.assertDictEqual(
{'20151010':
{'android_nexus_10':
{'count': 5, 'success_count': 2},
'android_nexus_4':
{'count': 5, 'success_count': 1}
},
'20151009':
},
'20151009':
{'win_xp':
{'count': 5, 'success_count': 5}
}
},
}
},
success_rates)

def testSummarizeSuccessRates(self):
rates = chrome_perf_stats._SummarizeSuccessRates(
{'20151010':
{'android_nexus_10':
{'count': 5, 'success_count': 2},
'android_nexus_4':
{'count': 5, 'success_count': 3}
},
'20151009':
},
'20151009':
{'win_xp':
{'count': 5, 'success_count': 5}
}
})
}
})
self.assertListEqual([['20151010', 0.5], ['20151009', 1.0]], rates)


if __name__ == '__main__':
unittest.main()
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,36 @@
'stats/last/chromium.perf/%s/%s/20')

IGNORED_STEPS = [
'List Perf Tests',
'Sharded Perf Tests',
'authorize_adb_devices',
'bot_update',
'build__schedule__time__',
'clean local files',
'cleanup_temp',
'device_status_check',
'extract build',
'gclient runhooks',
'get compile targets for scripts',
'get perf test list',
'gsutil download_build_product',
'host_info',
'install ChromeShell.apk',
'json.output cache',
'json.output cache',
'overall__build__result__',
'overall__queued__time__',
'provision_devices',
'read test spec',
'rmtree build directory',
'setup_build',
'spawn_logcat_monitor',
'stack_tool_for_tombstones',
'stack_tool_with_logcat_dump',
'steps',
'test_report',
'unzip_build_product',
'update_scripts'
'List Perf Tests',
'Sharded Perf Tests',
'authorize_adb_devices',
'bot_update',
'build__schedule__time__',
'clean local files',
'cleanup_temp',
'device_status_check',
'extract build',
'gclient runhooks',
'get compile targets for scripts',
'get perf test list',
'gsutil download_build_product',
'host_info',
'install ChromeShell.apk',
'json.output cache',
'json.output cache',
'overall__build__result__',
'overall__queued__time__',
'provision_devices',
'read test spec',
'rmtree build directory',
'setup_build',
'spawn_logcat_monitor',
'stack_tool_for_tombstones',
'stack_tool_with_logcat_dump',
'steps',
'test_report',
'unzip_build_product',
'update_scripts'
]

KNOWN_TESTERS_LIST = [
Expand Down Expand Up @@ -117,7 +117,7 @@
threshold_time = datetime.now() - timedelta(days=2)

col_names = [('builder', 'step', 'run_count', 'stddev', 'mean', 'maximum',
'median', 'seventyfive', 'ninety', 'ninetynine')]
'median', 'seventyfive', 'ninety', 'ninetynine')]
with open(outfilename, 'wb') as f:
writer = csv.writer(f)
writer.writerows(col_names)
Expand All @@ -128,7 +128,7 @@
response = urllib2.urlopen(url)
results = json.load(response)
steps = results['steps']
steps.sort() # to group tests and their references together.
steps.sort() # to group tests and their references together.
for step in steps:
if step in IGNORED_STEPS:
continue
Expand Down
1 change: 1 addition & 0 deletions catapult_base/catapult_base/refactor/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


class Module(object):

def __init__(self, file_path):
self._file_path = file_path

Expand Down
6 changes: 4 additions & 2 deletions catapult_base/catapult_base/refactor/offset_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class OffsetToken(object):
representing the content, and an offset. Using relative positions makes it
easy to insert and remove tokens.
"""

def __init__(self, token_type, string, offset):
self._type = token_type
self._string = string
Expand Down Expand Up @@ -72,9 +73,10 @@ def Tokenize(f):
else:
erow, ecol = prev_token[3]
if erow == srow:
offset_tokens.append(OffsetToken(token_type, string, (0, scol-ecol)))
offset_tokens.append(OffsetToken(token_type, string, (0, scol - ecol)))
else:
offset_tokens.append(OffsetToken(token_type, string, (srow-erow, scol)))
offset_tokens.append(OffsetToken(
token_type, string, (srow - erow, scol)))

return offset_tokens

Expand Down
4 changes: 3 additions & 1 deletion catapult_base/catapult_base/refactor/snippet.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class TokenSnippet(Snippet):
A list of tokens may start with any number of comments and non-terminating
newlines, but must end with a syntactically meaningful token.
"""

def __init__(self, token_type, tokens):
# For operators and delimiters, the TokenSnippet's type may be more specific
# than the type of the constituent token. E.g. the TokenSnippet type is
Expand Down Expand Up @@ -152,6 +153,7 @@ class Symbol(Snippet):
"""A Snippet containing sub-Snippets.
The possible types and type_names are defined in Python's symbol module."""

def __init__(self, symbol_type, children):
self._type = symbol_type
self._children = children
Expand Down Expand Up @@ -194,7 +196,7 @@ def PrintTree(self, indent=0, stream=sys.stdout):

print >> stream, node.type_name
for child in node.children:
child.PrintTree(indent+2, stream)
child.PrintTree(indent + 2, stream)


def Snippetize(f):
Expand Down
1 change: 1 addition & 0 deletions catapult_base/catapult_base/refactor_util/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def _Update(moves, module):


class _Move(object):

def __init__(self, source, target):
self._source_path = os.path.realpath(source)
self._target_path = os.path.realpath(target)
Expand Down
Loading

0 comments on commit 066bee6

Please sign in to comment.