/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: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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
    if not isinstance(node.args[1], ast.Str):
 
25
        # Not sure how to deal with this..
 
26
        return
 
27
    import_text = node.args[1].s
 
28
    scope = {}
 
29
    processor.lazy_import(scope, import_text)
 
30
    for name, (path, sub, scope) in processor.imports.items():
 
31
        importation = ImportationFrom(name, node, '.'.join(path), scope)
 
32
        self.addBinding(node, importation)
 
33
 
 
34
Checker.LAZY_IMPORT = LAZY_IMPORT
 
35
 
 
36
 
 
37
if __name__ == '__main__':
 
38
    from pyflakes import __main__
 
39
    __main__.main()