/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tools/brzflakes.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-10 17:18:27 UTC
  • mto: (7143.11.2 unused-imports)
  • mto: This revision was merged to the branch mainline in revision 7144.
  • Revision ID: jelmer@jelmer.uk-20181110171827-46xer5sa9fzgab1q
Add flake8 configuration to monkey patch for lazy imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
 
 
3
from __future__ import absolute_import
 
4
 
 
5
import ast
 
6
 
 
7
from pyflakes.checker import Checker, ImportationFrom
 
8
 
 
9
# Do some monkey patching..
 
10
def CALL(self, node):
 
11
    if isinstance(node.func, ast.Name) and node.func.id == 'lazy_import':
 
12
        self.LAZY_IMPORT(node)
 
13
    elif (isinstance(node.func, ast.Attribute) and
 
14
            node.func.attr == 'lazy_import' and
 
15
            node.func.value.id == 'lazy_import'):
 
16
        self.LAZY_IMPORT(node)
 
17
    return self.handleChildren(node)
 
18
 
 
19
Checker.CALL = CALL
 
20
 
 
21
def LAZY_IMPORT(self, node):
 
22
    from breezy.lazy_import import ImportProcessor
 
23
    processor = ImportProcessor()
 
24
    import_text = node.args[1].s
 
25
    scope = {}
 
26
    processor.lazy_import(scope, import_text)
 
27
    for name, (path, sub, scope) in processor.imports.items():
 
28
        importation = ImportationFrom(name, node, '.'.join(path), scope)
 
29
        self.addBinding(node, importation)
 
30
 
 
31
Checker.LAZY_IMPORT = LAZY_IMPORT
 
32
 
 
33
 
 
34
if __name__ == '__main__':
 
35
    from pyflakes import __main__
 
36
    __main__.main()