diff options
author | thestig <thestig@chromium.org> | 2015-01-15 15:19:23 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-15 23:20:10 +0000 |
commit | b179975134a3302cda4473240abcb74ecb45a6a0 (patch) | |
tree | 9ac643b63e82c3c367355f877edab9059922c1d1 /tools/json_schema_compiler | |
parent | e099f7cfd7a940d60592bff5f3ebb6b6c9fe2a8a (diff) | |
download | chromium_src-b179975134a3302cda4473240abcb74ecb45a6a0.zip chromium_src-b179975134a3302cda4473240abcb74ecb45a6a0.tar.gz chromium_src-b179975134a3302cda4473240abcb74ecb45a6a0.tar.bz2 |
Cleanup most pylint errors in json_schema_compiler.
Review URL: https://codereview.chromium.org/849103005
Cr-Commit-Position: refs/heads/master@{#311761}
Diffstat (limited to 'tools/json_schema_compiler')
-rw-r--r-- | tools/json_schema_compiler/cc_generator.py | 19 | ||||
-rwxr-xr-x | tools/json_schema_compiler/compiler.py | 4 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_bundle_generator.py | 2 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_type_generator.py | 18 | ||||
-rw-r--r-- | tools/json_schema_compiler/dart_generator.py | 6 | ||||
-rwxr-xr-x | tools/json_schema_compiler/features_compiler.py | 4 | ||||
-rw-r--r-- | tools/json_schema_compiler/h_generator.py | 4 | ||||
-rwxr-xr-x | tools/json_schema_compiler/idl_schema.py | 9 | ||||
-rw-r--r-- | tools/json_schema_compiler/model.py | 4 | ||||
-rwxr-xr-x | tools/json_schema_compiler/preview.py | 3 | ||||
-rw-r--r-- | tools/json_schema_compiler/schema_loader.py | 7 |
11 files changed, 38 insertions, 42 deletions
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py index 1d243f0..23056db 100644 --- a/tools/json_schema_compiler/cc_generator.py +++ b/tools/json_schema_compiler/cc_generator.py @@ -60,9 +60,9 @@ class _Generator(object): .Append('//') .Append() ) - for property in self._namespace.properties.values(): + for prop in self._namespace.properties.values(): property_code = self._type_helper.GeneratePropertyValues( - property, + prop, 'const %(type)s %(name)s = %(value)s;', nodoc=True) if property_code: @@ -454,8 +454,7 @@ class _Generator(object): # Results::Create function if function.callback: - c.Concat(self._GenerateCreateCallbackArguments(function_namespace, - 'Results', + c.Concat(self._GenerateCreateCallbackArguments('Results', function.callback)) c.Append('} // namespace %s' % function_namespace) @@ -467,10 +466,8 @@ class _Generator(object): event_namespace = cpp_util.Classname(event.name) (c.Append('namespace %s {' % event_namespace) .Append() - .Cblock(self._GenerateEventNameConstant(None, event)) - .Cblock(self._GenerateCreateCallbackArguments(event_namespace, - None, - event)) + .Cblock(self._GenerateEventNameConstant(event)) + .Cblock(self._GenerateCreateCallbackArguments(None, event)) .Append('} // namespace %s' % event_namespace) ) return c @@ -884,7 +881,6 @@ class _Generator(object): cpp_type_namespace = '' if type_.namespace != self._namespace: cpp_type_namespace = '%s::' % type_.namespace.unix_name - cpp_type_name = self._type_helper.GetCppType(type_) (c.Append('std::string %s;' % enum_as_string) .Sblock('if (!%s->GetAsString(&%s)) {' % (src_var, enum_as_string)) .Concat(self._GenerateError( @@ -965,7 +961,7 @@ class _Generator(object): c.Sblock('%s%s %sParse%s(const std::string& enum_string) {' % (maybe_namespace, classname, maybe_namespace, classname)) - for i, enum_value in enumerate( + for _, enum_value in enumerate( self._type_helper.FollowRef(type_).enum_values): # This is broken up into all ifs with no else ifs because we get # "fatal error C1061: compiler limit : blocks nested too deeply" @@ -979,7 +975,6 @@ class _Generator(object): return c def _GenerateCreateCallbackArguments(self, - cpp_namespace, function_scope, callback): """Generate all functions to create Value parameters for a callback. @@ -1017,7 +1012,7 @@ class _Generator(object): }) return c - def _GenerateEventNameConstant(self, function_scope, event): + def _GenerateEventNameConstant(self, event): """Generates a constant string array for the event name. """ c = Code() diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py index 7a2e4dd..0b14d29 100755 --- a/tools/json_schema_compiler/compiler.py +++ b/tools/json_schema_compiler/compiler.py @@ -85,7 +85,7 @@ def GenerateSchema(generator_name, else: src_path = os.path.commonprefix((src_path, namespace.source_file_dir)) - path, filename = os.path.split(file_path) + _, filename = os.path.split(file_path) filename_base, _ = os.path.splitext(filename) # Construct the type generator with all the namespaces in this model. @@ -123,7 +123,7 @@ def GenerateSchema(generator_name, dart_overrides_dir)) ] else: - raise Exception('Unrecognised generator %s' % generator) + raise Exception('Unrecognised generator %s' % generator_name) output_code = [] for filename, generator in generators: diff --git a/tools/json_schema_compiler/cpp_bundle_generator.py b/tools/json_schema_compiler/cpp_bundle_generator.py index 0a4f9a6..708d30f 100644 --- a/tools/json_schema_compiler/cpp_bundle_generator.py +++ b/tools/json_schema_compiler/cpp_bundle_generator.py @@ -125,8 +125,6 @@ class CppBundleGenerator(object): if namespace_ifdefs is not None: c.Append("#if %s" % namespace_ifdefs, indent_level=0) - namespace_name = CapitalizeFirstLetter(namespace.name.replace( - "experimental.", "")) for function in namespace.functions.values(): if function.nocompile: continue diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py index 6bec67e4..44ff978 100644 --- a/tools/json_schema_compiler/cpp_type_generator.py +++ b/tools/json_schema_compiler/cpp_type_generator.py @@ -244,30 +244,30 @@ class CppTypeGenerator(object): deps |= self._TypeDependencies(p.type_, hard=not p.optional) return deps - def GeneratePropertyValues(self, property, line, nodoc=False): + def GeneratePropertyValues(self, prop, line, nodoc=False): """Generates the Code to display all value-containing properties. """ c = Code() if not nodoc: - c.Comment(property.description) + c.Comment(prop.description) - if property.value is not None: + if prop.value is not None: c.Append(line % { - "type": self.GetCppType(property.type_), - "name": property.name, - "value": property.value + "type": self.GetCppType(prop.type_), + "name": prop.name, + "value": prop.value }) else: has_child_code = False - c.Sblock('namespace %s {' % property.name) - for child_property in property.type_.properties.values(): + c.Sblock('namespace %s {' % prop.name) + for child_property in prop.type_.properties.values(): child_code = self.GeneratePropertyValues(child_property, line, nodoc=nodoc) if child_code: has_child_code = True c.Concat(child_code) - c.Eblock('} // namespace %s' % property.name) + c.Eblock('} // namespace %s' % prop.name) if not has_child_code: c = None return c diff --git a/tools/json_schema_compiler/dart_generator.py b/tools/json_schema_compiler/dart_generator.py index a9ba0d6..74ffd11 100644 --- a/tools/json_schema_compiler/dart_generator.py +++ b/tools/json_schema_compiler/dart_generator.py @@ -191,7 +191,7 @@ class _Generator(object): else self._GenerateGetter(type_, prop)) override = self._GetOverride([type_.name, prop.name, '.set']) c.Cblock(override if override is not None - else self._GenerateSetter(type_, prop)) + else self._GenerateSetter(prop)) return c def _GenerateGetter(self, type_, prop): @@ -241,8 +241,8 @@ class _Generator(object): ) return c - def _GenerateSetter(self, type_, prop): - """Given a Type and Property, returns the Code object for the setter for + def _GenerateSetter(self, prop): + """Given a Property, returns the Code object for the setter for that property. """ c = Code() diff --git a/tools/json_schema_compiler/features_compiler.py b/tools/json_schema_compiler/features_compiler.py index 1e4e81a..cb3f7ef 100755 --- a/tools/json_schema_compiler/features_compiler.py +++ b/tools/json_schema_compiler/features_compiler.py @@ -23,7 +23,9 @@ def _GenerateSchema(filename, root, destdir, namespace): # Load in the feature permissions from the JSON file. schema = os.path.normpath(filename) schema_loader = SchemaLoader(os.path.dirname(os.path.relpath(schema, root)), - os.path.dirname(schema)) + os.path.dirname(schema), + [], + None) schema_filename = os.path.splitext(schema)[0] feature_defs = schema_loader.LoadSchema(schema) diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py index a6d67db..33d7a6e 100644 --- a/tools/json_schema_compiler/h_generator.py +++ b/tools/json_schema_compiler/h_generator.py @@ -74,9 +74,9 @@ class _Generator(object): .Append('//') .Append() ) - for property in self._namespace.properties.values(): + for prop in self._namespace.properties.values(): property_code = self._type_helper.GeneratePropertyValues( - property, + prop, 'extern const %(type)s %(name)s;') if property_code: c.Cblock(property_code) diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py index a913756..45f0609 100755 --- a/tools/json_schema_compiler/idl_schema.py +++ b/tools/json_schema_compiler/idl_schema.py @@ -271,7 +271,6 @@ class Typeref(object): properties['additionalProperties'] = OrderedDict() properties['additionalProperties']['type'] = 'any' elif self.parent.GetPropertyLocal('Union'): - choices = [] properties['choices'] = [Typeref(node.GetProperty('TYPEREF'), node, OrderedDict()).process(callbacks) @@ -303,7 +302,7 @@ class Enum(object): self.node = enum_node self.description = '' - def process(self, callbacks): + def process(self): enum = [] for node in self.node.GetChildren(): if node.cls == 'EnumItem': @@ -327,7 +326,7 @@ class Enum(object): if self.node.GetProperty(property_name): result[property_name] = self.node.GetProperty(property_name) if self.node.GetProperty('deprecated'): - result[deprecated] = self.node.GetProperty('deprecated') + result['deprecated'] = self.node.GetProperty('deprecated') return result @@ -369,7 +368,7 @@ class Namespace(object): elif node.cls == 'Interface' and node.GetName() == 'Events': self.events = self.process_interface(node) elif node.cls == 'Enum': - self.types.append(Enum(node).process(self.callbacks)) + self.types.append(Enum(node).process()) else: sys.exit('Did not process %s %s' % (node.cls, node)) if self.compiler_options is not None: @@ -391,7 +390,7 @@ class Namespace(object): members = [] for member in node.GetChildren(): if member.cls == 'Member': - name, properties = Member(member).process(self.callbacks) + _, properties = Member(member).process(self.callbacks) members.append(properties) return members diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py index 16530e7..7745dcc 100644 --- a/tools/json_schema_compiler/model.py +++ b/tools/json_schema_compiler/model.py @@ -304,8 +304,8 @@ class Function(object): def GeneratePropertyFromParam(p): return Property(self, p['name'], p, namespace, origin) - self.filters = [GeneratePropertyFromParam(filter) - for filter in json.get('filters', [])] + self.filters = [GeneratePropertyFromParam(filter_instance) + for filter_instance in json.get('filters', [])] callback_param = None for param in json.get('parameters', []): if param.get('type') == 'function': diff --git a/tools/json_schema_compiler/preview.py b/tools/json_schema_compiler/preview.py index 050af96..aceb575 100755 --- a/tools/json_schema_compiler/preview.py +++ b/tools/json_schema_compiler/preview.py @@ -201,7 +201,6 @@ updateEverything(); namespace) # Generate code - cpp_namespace = 'generated_api_schemas' if file_ext == '.h': cpp_code = (h_generator.HGenerator(type_generator) .Generate(namespace).Render()) @@ -286,7 +285,7 @@ updateEverything(); # Each file under path/ for filename in sorted(os.listdir(path)): full_path = os.path.join(path, filename) - (file_root, file_ext) = os.path.splitext(full_path) + _, file_ext = os.path.splitext(full_path) if os.path.isdir(full_path) and not full_path.endswith('.xcodeproj'): html.Append('<li><a href="/%s/">%s/</a>' % (full_path, filename)) elif file_ext in ['.json', '.idl']: diff --git a/tools/json_schema_compiler/schema_loader.py b/tools/json_schema_compiler/schema_loader.py index b896991..aad661e 100644 --- a/tools/json_schema_compiler/schema_loader.py +++ b/tools/json_schema_compiler/schema_loader.py @@ -54,13 +54,16 @@ class SchemaLoader(object): def ResolveNamespace(self, full_namespace): filenames = GenerateFilenames(full_namespace) for path, cpp_namespace in self._include_rules: + cpp_namespace_environment = None + if cpp_namespace: + cpp_namespace_environment = CppNamespaceEnvironment(cpp_namespace) for filename in reversed(filenames): filepath = os.path.join(path, filename); if os.path.exists(os.path.join(self._root, filepath)): return Model().AddNamespace( self.LoadSchema(filepath)[0], filepath, - environment=CppNamespaceEnvironment(cpp_namespace)) + environment=cpp_namespace_environment) return None def ResolveType(self, full_name, default_namespace): @@ -78,7 +81,7 @@ class SchemaLoader(object): def LoadSchema(self, schema): '''Load a schema definition. The schema parameter must be a file name with the full path relative to the root.''' - schema_filename, schema_extension = os.path.splitext(schema) + _, schema_extension = os.path.splitext(schema) schema_path = os.path.join(self._root, schema) if schema_extension == '.json': |