Processor to handle suppression of OK'd PyChecker, PyFlakes and PyCodeStyle (Pep8) warning messages, marked as such at the end of the Python source code line.
| 256 | |
| 257 | |
| 258 | class Processor(object): |
| 259 | '''Processor to handle suppression of OK'd PyChecker, PyFlakes |
| 260 | and PyCodeStyle (Pep8) warning messages, marked as such at |
| 261 | the end of the Python source code line. |
| 262 | ''' |
| 263 | _code = [] # source code lines |
| 264 | _dirs = () # source file directories |
| 265 | _name = '' # source file name |
| 266 | |
| 267 | _cmds = () # commands to run |
| 268 | _debug = _Debug # print debug output |
| 269 | _OKd = _OKd # print OK'd warnings |
| 270 | _out = _Out # output file, None for quiet |
| 271 | _title = True # print module title |
| 272 | _x3 = _X3 # run Python 3+ checkers |
| 273 | |
| 274 | def __init__(self, cmds, OKd=_OKd, debug=_Debug, out=_Out, x3=False): |
| 275 | self._debug = debug |
| 276 | self._OKd = OKd |
| 277 | self._out = out |
| 278 | self._cmds = [] |
| 279 | for c in cmds.split(_and): |
| 280 | c = c.split() |
| 281 | try: |
| 282 | x = c[0] # checker |
| 283 | if x3 and not x.endswith('3'): |
| 284 | x += '3' |
| 285 | c[0] = x = which(x) |
| 286 | self._cmds.append(' '.join(c)) |
| 287 | if 'pychecker' in x.lower(): |
| 288 | self._title = False # don't print |
| 289 | self._x3 = x3 |
| 290 | except OSError: |
| 291 | self.printf('%s warning: %s', _argv0, sys.exc_info()[1]) |
| 292 | |
| 293 | def allist(self, name): |
| 294 | '''Check that the objects named in the |
| 295 | __all__ list do exist in the module. |
| 296 | ''' |
| 297 | self.debugf("running '%s %s' ...", 'allist', name) |
| 298 | n, w = 0, [] |
| 299 | try: |
| 300 | m = __import__(name[:-3]) |
| 301 | except ImportError: |
| 302 | m = None |
| 303 | for a in getattr(m, '__all__', []): |
| 304 | if not hasattr(m, a): |
| 305 | if not n: # get __all__ line number, once |
| 306 | if name != self._name: |
| 307 | self.get(name) |
| 308 | for i, t in enumerate(self._code): |
| 309 | if t.startswith('__all__'): |
| 310 | n = i + 1 |
| 311 | break |
| 312 | w.append('%s:%d: no %s object %r in module %r' % |
| 313 | (name, n, '__all__', a, m.__name__)) |
| 314 | self.debugf('%s of %r output', plural(len(w), 'line'), 'allist') |
| 315 | return tuple(w) |
no outgoing calls
no test coverage detected