/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-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

Show diffs side-by-side

added added

removed removed

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