зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1344718 - Enable flake8 rule E302: "expected 2 blank lines, found 1" for Telemetry code. r=Dexter
--HG-- extra : rebase_source : a9f3cbd3e06dbe594497c544768515ee070e268c
This commit is contained in:
Родитель
bc2c7e65ad
Коммит
1c309ba4b2
|
@ -1,5 +1,5 @@
|
|||
[flake8]
|
||||
# See http://pep8.readthedocs.io/en/latest/intro.html#configuration
|
||||
ignore = E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402, E302, E703, E502, E128, E501, E713, E231, E111, E261, E222, E203, E201, E202, W602, E127, F841, F401, W601
|
||||
ignore = E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402, E703, E502, E128, E501, E713, E231, E111, E261, E222, E203, E201, E202, W602, E127, F841, F401, W601
|
||||
max-line-length = 99
|
||||
filename = *.py, +.lint
|
||||
|
|
|
@ -29,6 +29,7 @@ file_footer = """\
|
|||
#endif // mozilla_TelemetryEventData_h
|
||||
"""
|
||||
|
||||
|
||||
def write_extra_table(events, output, string_table):
|
||||
table_name = "gExtraKeysTable"
|
||||
extra_table = []
|
||||
|
@ -61,6 +62,7 @@ def write_extra_table(events, output, string_table):
|
|||
|
||||
return extra_table
|
||||
|
||||
|
||||
def write_common_event_table(events, output, string_table, extra_table):
|
||||
table_name = "gCommonEventInfo"
|
||||
extra_count = 0
|
||||
|
@ -87,6 +89,7 @@ def write_common_event_table(events, output, string_table, extra_table):
|
|||
static_assert(output, "sizeof(%s) <= UINT32_MAX" % table_name,
|
||||
"index overflow")
|
||||
|
||||
|
||||
def write_event_table(events, output, string_table):
|
||||
table_name = "gEventInfo"
|
||||
print("const EventInfo %s[] = {" % table_name, file=output)
|
||||
|
@ -107,6 +110,7 @@ def write_event_table(events, output, string_table):
|
|||
static_assert(output, "sizeof(%s) <= UINT32_MAX" % table_name,
|
||||
"index overflow")
|
||||
|
||||
|
||||
def main(output, *filenames):
|
||||
# Load the event data.
|
||||
if len(filenames) > 1:
|
||||
|
|
|
@ -29,6 +29,7 @@ file_footer = """\
|
|||
#endif // mozilla_TelemetryEventEnums_h
|
||||
"""
|
||||
|
||||
|
||||
def main(output, *filenames):
|
||||
# Load the events first.
|
||||
if len(filenames) > 1:
|
||||
|
|
|
@ -13,6 +13,7 @@ import json
|
|||
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
def main(argv):
|
||||
filenames = argv
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import itertools
|
|||
banner = """/* This file is auto-generated, see gen-histogram-data.py. */
|
||||
"""
|
||||
|
||||
|
||||
def print_array_entry(output, histogram, name_index, exp_index, label_index, label_count):
|
||||
cpp_guard = histogram.cpp_guard()
|
||||
if cpp_guard:
|
||||
|
@ -33,6 +34,7 @@ def print_array_entry(output, histogram, name_index, exp_index, label_index, lab
|
|||
if cpp_guard:
|
||||
print("#endif", file=output)
|
||||
|
||||
|
||||
def write_histogram_table(output, histograms):
|
||||
string_table = StringTable()
|
||||
label_table = []
|
||||
|
@ -74,17 +76,21 @@ def write_histogram_table(output, histograms):
|
|||
def static_asserts_for_boolean(output, histogram):
|
||||
pass
|
||||
|
||||
|
||||
def static_asserts_for_flag(output, histogram):
|
||||
pass
|
||||
|
||||
|
||||
def static_asserts_for_count(output, histogram):
|
||||
pass
|
||||
|
||||
|
||||
def static_asserts_for_enumerated(output, histogram):
|
||||
n_values = histogram.high()
|
||||
static_assert(output, "%s > 2" % n_values,
|
||||
"Not enough values for %s" % histogram.name())
|
||||
|
||||
|
||||
def shared_static_asserts(output, histogram):
|
||||
name = histogram.name()
|
||||
low = histogram.low()
|
||||
|
@ -96,12 +102,15 @@ def shared_static_asserts(output, histogram):
|
|||
static_assert(output, "%s > %s" % (high, n_buckets),
|
||||
"high must be > number of buckets for %s; you may want an enumerated histogram" % name)
|
||||
|
||||
|
||||
def static_asserts_for_linear(output, histogram):
|
||||
shared_static_asserts(output, histogram)
|
||||
|
||||
|
||||
def static_asserts_for_exponential(output, histogram):
|
||||
shared_static_asserts(output, histogram)
|
||||
|
||||
|
||||
def write_histogram_static_asserts(output, histograms):
|
||||
print("""
|
||||
// Perform the checks at the beginning of HistogramGet at
|
||||
|
@ -122,6 +131,7 @@ def write_histogram_static_asserts(output, histograms):
|
|||
histogram_tools.table_dispatch(histogram.kind(), table,
|
||||
lambda f: f(output, histogram))
|
||||
|
||||
|
||||
def write_debug_histogram_ranges(output, histograms):
|
||||
ranges_lengths = []
|
||||
|
||||
|
@ -166,6 +176,7 @@ def write_debug_histogram_ranges(output, histograms):
|
|||
print("};", file=output)
|
||||
print("#endif", file=output)
|
||||
|
||||
|
||||
def main(output, *filenames):
|
||||
histograms = list(histogram_tools.from_files(filenames))
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ footer = """
|
|||
} // namespace Telemetry
|
||||
#endif // mozilla_TelemetryHistogramEnums_h"""
|
||||
|
||||
|
||||
def main(output, *filenames):
|
||||
# Print header.
|
||||
print(banner, file=output)
|
||||
|
|
|
@ -28,6 +28,7 @@ file_footer = """\
|
|||
#endif // mozilla_TelemetryScalarData_h
|
||||
"""
|
||||
|
||||
|
||||
def write_scalar_info(scalar, output, name_index, expiration_index):
|
||||
"""Writes a scalar entry to the output file.
|
||||
|
||||
|
@ -52,6 +53,7 @@ def write_scalar_info(scalar, output, name_index, expiration_index):
|
|||
if cpp_guard:
|
||||
print("#endif", file=output)
|
||||
|
||||
|
||||
def write_scalar_tables(scalars, output):
|
||||
"""Writes the scalar and strings tables to an header file.
|
||||
|
||||
|
@ -75,6 +77,7 @@ def write_scalar_tables(scalars, output):
|
|||
static_assert(output, "sizeof(%s) <= UINT32_MAX" % string_table_name,
|
||||
"index overflow")
|
||||
|
||||
|
||||
def main(output, *filenames):
|
||||
# Load the scalars first.
|
||||
if len(filenames) > 1:
|
||||
|
|
|
@ -30,6 +30,7 @@ file_footer = """\
|
|||
#endif // mozilla_TelemetryScalarEnums_h
|
||||
"""
|
||||
|
||||
|
||||
def main(output, *filenames):
|
||||
# Load the scalars first.
|
||||
if len(filenames) > 1:
|
||||
|
|
|
@ -33,6 +33,7 @@ except ImportError:
|
|||
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
def table_dispatch(kind, table, body):
|
||||
"""Call body with table[kind] if it exists. Raise an error otherwise."""
|
||||
if kind in table:
|
||||
|
@ -40,9 +41,11 @@ def table_dispatch(kind, table, body):
|
|||
else:
|
||||
raise BaseException, "don't know how to handle a histogram of kind %s" % kind
|
||||
|
||||
|
||||
class DefinitionException(BaseException):
|
||||
pass
|
||||
|
||||
|
||||
def linear_buckets(dmin, dmax, n_buckets):
|
||||
ret_array = [0] * n_buckets
|
||||
dmin = float(dmin)
|
||||
|
@ -52,6 +55,7 @@ def linear_buckets(dmin, dmax, n_buckets):
|
|||
ret_array[i] = int(linear_range + 0.5)
|
||||
return ret_array
|
||||
|
||||
|
||||
def exponential_buckets(dmin, dmax, n_buckets):
|
||||
log_max = math.log(dmax);
|
||||
bucket_index = 2;
|
||||
|
@ -88,6 +92,7 @@ except IOError:
|
|||
whitelists = None
|
||||
print 'Unable to parse whitelist (%s). Assuming all histograms are acceptable.' % whitelist_path
|
||||
|
||||
|
||||
class Histogram:
|
||||
"""A class for representing a histogram definition."""
|
||||
|
||||
|
@ -422,6 +427,7 @@ associated with the histogram. Returns None if no guarding is necessary."""
|
|||
definition['high'],
|
||||
definition['n_buckets'])
|
||||
|
||||
|
||||
# We support generating histograms from multiple different input files, not
|
||||
# just Histograms.json. For each file's basename, we have a specific
|
||||
# routine to parse that file, and return a dictionary mapping histogram
|
||||
|
@ -434,9 +440,11 @@ def from_Histograms_json(filename):
|
|||
raise BaseException, "error parsing histograms in %s: %s" % (filename, e.message)
|
||||
return histograms
|
||||
|
||||
|
||||
def from_UseCounters_conf(filename):
|
||||
return usecounters.generate_histograms(filename)
|
||||
|
||||
|
||||
def from_nsDeprecatedOperationList(filename):
|
||||
operation_regex = re.compile('^DEPRECATED_OPERATION\\(([^)]+)\\)')
|
||||
histograms = collections.OrderedDict()
|
||||
|
@ -475,6 +483,7 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def from_files(filenames):
|
||||
"""Return an iterator that provides a sequence of Histograms for
|
||||
the histograms defined in filenames.
|
||||
|
|
|
@ -18,14 +18,17 @@ MAX_EXTRA_KEY_NAME_LENGTH = 15
|
|||
IDENTIFIER_PATTERN = r'^[a-zA-Z][a-zA-Z0-9_.]+[a-zA-Z0-9]$'
|
||||
DATE_PATTERN = r'^[0-9]{4}-[0-9]{2}-[0-9]{2}$'
|
||||
|
||||
|
||||
def nice_type_name(t):
|
||||
if isinstance(t, basestring):
|
||||
return "string"
|
||||
return t.__name__
|
||||
|
||||
|
||||
def convert_to_cpp_identifier(s, sep):
|
||||
return string.capwords(s, sep).replace(sep, "")
|
||||
|
||||
|
||||
class OneOf:
|
||||
"""This is a placeholder type for the TypeChecker below.
|
||||
It signals that the checked value should match one of the following arguments
|
||||
|
@ -33,6 +36,7 @@ class OneOf:
|
|||
"""
|
||||
pass
|
||||
|
||||
|
||||
class TypeChecker:
|
||||
"""This implements a convenience type TypeChecker to make the validation code more readable."""
|
||||
def __init__(self, kind, *args):
|
||||
|
@ -92,6 +96,7 @@ class TypeChecker:
|
|||
k,
|
||||
nice_type_name(type(x)))
|
||||
|
||||
|
||||
def type_check_event_fields(identifier, name, definition):
|
||||
"""Perform a type/schema check on the event definition."""
|
||||
REQUIRED_FIELDS = {
|
||||
|
@ -125,6 +130,7 @@ def type_check_event_fields(identifier, name, definition):
|
|||
for k,v in definition.iteritems():
|
||||
ALL_FIELDS[k].check(identifier, k, v)
|
||||
|
||||
|
||||
def string_check(identifier, field, value, min_length=1, max_length=None, regex=None):
|
||||
# Length check.
|
||||
if len(value) < min_length:
|
||||
|
@ -138,6 +144,7 @@ def string_check(identifier, field, value, min_length=1, max_length=None, regex=
|
|||
raise ValueError, '%s: string value "%s" for %s is not matching pattern "%s"' % \
|
||||
(identifier, value, field, regex)
|
||||
|
||||
|
||||
class EventData:
|
||||
"""A class representing one event."""
|
||||
|
||||
|
@ -275,6 +282,7 @@ class EventData:
|
|||
def extra_keys(self):
|
||||
return self._definition.get('extra_keys', {}).keys()
|
||||
|
||||
|
||||
def load_events(filename):
|
||||
"""Parses a YAML file containing the event definitions.
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ SCALAR_TYPES_MAP = {
|
|||
'boolean': 'nsITelemetry::SCALAR_BOOLEAN'
|
||||
}
|
||||
|
||||
|
||||
class ScalarType:
|
||||
"""A class for representing a scalar definition."""
|
||||
|
||||
|
@ -243,6 +244,7 @@ class ScalarType:
|
|||
"""Get the cpp guard for this scalar"""
|
||||
return self._definition.get('cpp_guard')
|
||||
|
||||
|
||||
def load_scalars(filename):
|
||||
"""Parses a YAML file containing the scalar definition.
|
||||
|
||||
|
|
|
@ -21,12 +21,15 @@ KNOWN_PROCESS_FLAGS = {
|
|||
|
||||
PROCESS_ENUM_PREFIX = "mozilla::Telemetry::Common::RecordedProcessType::"
|
||||
|
||||
|
||||
def is_valid_process_name(name):
|
||||
return (name in KNOWN_PROCESS_FLAGS)
|
||||
|
||||
|
||||
def process_name_to_enum(name):
|
||||
return PROCESS_ENUM_PREFIX + KNOWN_PROCESS_FLAGS.get(name)
|
||||
|
||||
|
||||
class StringTable:
|
||||
"""Manages a string table and allows C style serialization to a file."""
|
||||
|
||||
|
@ -97,6 +100,7 @@ class StringTable:
|
|||
f.write(" /* %5d - \"%s\" */ '\\0',\n" % (offset, string))
|
||||
f.write("};\n\n")
|
||||
|
||||
|
||||
def static_assert(output, expression, message):
|
||||
"""Writes a C++ compile-time assertion expression to a file.
|
||||
:param output: the output stream.
|
||||
|
@ -106,6 +110,7 @@ def static_assert(output, expression, message):
|
|||
"""
|
||||
print("static_assert(%s, \"%s\");" % (expression, message), file=output)
|
||||
|
||||
|
||||
def add_expiration_postfix(expiration):
|
||||
""" Formats the expiration version and adds a version postfix if needed.
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче