diff --git a/.travis.yml b/.travis.yml index de1ad63..7fe3108 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,17 @@ before-install: install: - pip install -r requirements.txt + - git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git script: + # Run the unittests - python -m unittest discover --start-directory stl/ --pattern "*_test.py" - python -m unittest discover --start-directory example/ --pattern "*_test.py" + # Run the linter + - depot_tools/pylint stl --ignore=parsetab.py,parser_test_proto_pb2.py + - depot_tools/pylint example --ignore=example_pb2.py + notification: email: - sprockets-eng@googlegroups.com diff --git a/stl/base.py b/stl/base.py index 02b0b99..07ebe67 100644 --- a/stl/base.py +++ b/stl/base.py @@ -89,6 +89,9 @@ def __init__(self, name): def __eq__(self, other): return NamedObject.__eq__(self, other) and self.params == other.params + def Resolve(self, env, resolved_params): + raise NotImplementedError('Resolved() is not needed: ' + self.name) + class TypedObject(NamedObject): """Base class for all object with a type and name. @@ -104,6 +107,9 @@ def __init__(self, name, type_): def __eq__(self, other): return NamedObject.__eq__(self, other) and self.type_ == other.type_ + def Resolve(self, env, resolved_params): + raise NotImplementedError('Resolved() is not needed: ' + self.name) + class Const(TypedObject): """Constants. @@ -333,6 +339,9 @@ def __init__(self, name, type_): def __str__(self): return 'PARAM %s(%s)' % (self.name, self.type_) + def Resolve(self, env, resolved_params): + raise NotImplementedError('Resolved() is not needed: ' + self.name) + class LocalVar(TypedObject): """Local variables. @@ -352,6 +361,9 @@ def __init__(self, name, type_): def __str__(self): return 'LOCAL %s(%s)' % (self.name, self.type_) + def Resolve(self, env, resolved_params): + raise NotImplementedError('Resolved() is not needed: ' + self.name) + class Field(TypedObject): """Fields in messages or in roles. @@ -384,6 +396,9 @@ def __str__(self): return 'FIELD-OPTIONAL %s(%s)' % (self.name, self.type_) return 'FIELD %s(%s)' % (self.name, self.type_) + def Resolve(self, env, resolved_params): + raise NotImplementedError('Resolved() is not needed: ' + self.name) + class Role(NamedObject): """Roles. @@ -522,6 +537,9 @@ def Run(self): raise RuntimeError('Func does not contain a runnable function.') return self.func(*self.args) + def Resolve(self, env, resolved_params): + raise NotImplementedError('Resolved() is not needed: ' + self.name) + class FuncNoOp(Func): """External function doing nothing.""" @@ -532,6 +550,9 @@ def __init__(self, name): def Run(self): return True + def Resolve(self, env, resolved_params): + raise NotImplementedError('Resolved() is not needed: ' + self.name) + class FuncGetField(Func): """External function to get the value of a field either of Role or dictionary. @@ -555,6 +576,9 @@ def __str__(self): def Run(self): return self.obj[self.field] + def Resolve(self, env, resolved_params): + raise NotImplementedError('Resolved() is not needed: ' + self.name) + class FuncSet(Func): """External function to set a value to a field of Role or to a LocalVar. @@ -603,6 +627,9 @@ def SetValue(self, value): else: raise TypeError('Cannot SetValue on type %s' % type(self.obj)) + def Resolve(self, env, resolved_params): + raise NotImplementedError('Resolved() is not needed: ' + self.name) + class FuncWithContext(Func): """External event function with context. @@ -651,3 +678,6 @@ def Run(self): if self.context.test_source: return self.event.Wait(*new_args) return self.event.Fire(*new_args) + + def Resolve(self, env, resolved_params): + raise NotImplementedError('Resolved() is not needed: ' + self.name) diff --git a/stl/lexer.py b/stl/lexer.py index 211f5ac..8d43e23 100644 --- a/stl/lexer.py +++ b/stl/lexer.py @@ -15,17 +15,10 @@ """Lexing (tokenizing) a state transition (STL) spec.""" -# pylint: disable=g-doc-args -# pylint: disable=g-docstring-missing-newline -# pylint: disable=g-docstring-quotes -# pylint: disable=g-no-space-after-docstring-summary -# pylint: disable=g-short-docstring-punctuation -# pylint: disable=g-short-docstring-space -# pylint: disable=invalid-name -# pylint: disable=unused-variable import logging -import ply.lex # pylint: disable=g-bad-import-order + +import ply.lex class StlSyntaxError(SyntaxError): @@ -136,7 +129,7 @@ def t_error(self, t): t.value[0]) t.lexer.skip(1) - def debug(data): - """Print out all the tokens in |data|.""" + def debug(self): + """Print out all the tokens from the lexer|.""" for token in self.lexer.tokens(): print token diff --git a/stl/lib.py b/stl/lib.py index f6670bf..ea8b7e0 100644 --- a/stl/lib.py +++ b/stl/lib.py @@ -293,11 +293,11 @@ class DifferentFrom(Qualifier): def __init__(self): Qualifier.__init__(self) - def Validate(self, value, prev): + def Validate(self, value, prev): # pylint: disable=arguments-differ # This value must not match the previous one. return value != prev - def Generate(self, prev): + def Generate(self, prev): # pylint: disable=arguments-differ rand = random.randint(0, 999999) if 'random-%s' % rand == prev: rand += 1 diff --git a/stl/message.py b/stl/message.py index 7b431c7..d85886f 100644 --- a/stl/message.py +++ b/stl/message.py @@ -15,11 +15,12 @@ import importlib import logging + from google.protobuf import message from google.protobuf import reflection -import stl.base # pylint: disable=g-bad-import-order -import stl.lib # pylint: disable=g-bad-import-order +import stl.base +import stl.lib class Message(stl.base.NamedObject): diff --git a/stl/parser.py b/stl/parser.py index d5e4b12..fb14216 100644 --- a/stl/parser.py +++ b/stl/parser.py @@ -14,20 +14,12 @@ # limitations under the License. """Parsing a state transition spec.""" -# pylint: disable=g-doc-args -# pylint: disable=g-docstring-missing-newline -# pylint: disable=g-docstring-quotes -# pylint: disable=g-no-space-after-docstring-summary -# pylint: disable=g-short-docstring-punctuation -# pylint: disable=g-short-docstring-space -# pylint: disable=invalid-name -# pylint: disable=unused-variable - import logging -import ply.yacc # pylint: disable=g-bad-import-order import pprint import sys +import ply.yacc + import stl.base import stl.event import stl.lexer @@ -98,19 +90,22 @@ def p_const_def(self, p): """const_def : CONST type NAME ';' | CONST type NAME '=' value ';' """ if self._local_env['_curr_module'].HasDefinition(p[3]): - logging.error('[%s:%d] Duplicated const: %s', self._filename, p.lineno(3), p[3]) + logging.error( + '[%s:%d] Duplicated const: %s', self._filename, p.lineno(3), p[3]) return # TODO(byungchul): Type checking if len(p) == 5: self._local_env['_curr_module'].consts[p[3]] = stl.base.Const(p[3], p[2]) else: - self._local_env['_curr_module'].consts[p[3]] = stl.base.Const(p[3], p[2], p[5]) + self._local_env['_curr_module'].consts[p[3]] = ( + stl.base.Const(p[3], p[2], p[5])) def p_role_def(self, p): """role_def : ROLE NAME '{' '}' | ROLE NAME '{' role_fields '}' """ if self._local_env['_curr_module'].HasDefinition(p[2]): - logging.error('[%s:%d] Duplicated role: %s', self._filename, p.lineno(2), p[2]) + logging.error( + '[%s:%d] Duplicated role: %s', self._filename, p.lineno(2), p[2]) return role = stl.base.Role(p[2]) if len(p) >= 6: @@ -142,7 +137,8 @@ def p_state_def(self, p): """state_def : STATE NAME params '{' names '}' | STATE NAME params '{' names ',' '}' """ if self._local_env['_curr_module'].HasDefinition(p[2]): - logging.error('[%s:%d] Duplicated state: %s', self._filename, p.lineno(2), p[2]) + logging.error( + '[%s:%d] Duplicated state: %s', self._filename, p.lineno(2), p[2]) return state_ = stl.state.State(p[2]) state_.params = p[3] @@ -249,7 +245,8 @@ def p_field_property_list(self, p): assert isinstance(p[1], dict) key, val = p[3] if key in p[1]: - logging.error('[%s:%d] Duplicated key: %s', self._filename, p.lineno(3), key) + logging.error( + '[%s:%d] Duplicated key: %s', self._filename, p.lineno(3), key) return p[1][key] = val p[0] = p[1] diff --git a/stl/qualifier.py b/stl/qualifier.py index e258353..19085c4 100644 --- a/stl/qualifier.py +++ b/stl/qualifier.py @@ -71,5 +71,6 @@ def __str__(self): return '%s b(%s)' % (Qualifier.__str__(self), self.external_name) def Resolve(self, env, resolved_params): + del env, resolved_params # Unused. logging.log(1, 'Resolving ' + self.name) return self.external