def __init__(self, tree):
        """Initialize package setup visitor."""
        self.redirected = False
        self.keywords = {}

        # Find setup() call and redirect it.
        self.visit(tree)

        if not self.redirected:
            return

        def setup(**kw):
            """Setup() arguments hijacking."""
            self.keywords = kw

        # XXX: If evaluated script (setup.py) depends on local modules we
        #      have to add its root directory to the import search path.
        #      Note however, that this hack might break further imports
        #      for OUR Python instance (we're changing our own sys.path)!
        sys.path.insert(0, os.getcwd())

        try:
            tree = ast.fix_missing_locations(tree)
            eval(compile(tree, "<str>", mode='exec'), {
                '__name__': "__main__",
                '__file__': "setup.py",
                '__f8r_setup': setup,
            })
        except Exception as e:
            # XXX: Exception during setup.py evaluation might not necessary
            #      mean "fatal error". This exception might occur if e.g.
            #      we have hijacked local setup() function (due to matching
            #      heuristic for function arguments). Anyway, we shall not
            #      break flake8 execution due to out eval() usage.
            LOG.exception("Couldn't evaluate setup.py: %s", e)

        # Restore import search path.
        sys.path.pop(0)
def __init__ ( self , tree ) : self . redirected = False self . keywords = { } self . visit ( tree ) if not self . redirected : return def setup ( ** kw ) : self . keywords = kw sys . path . insert ( 0 , os . getcwd ( ) ) try : tree = ast . fix_missing_locations ( tree ) eval ( compile ( tree , "<str>" , mode = 'exec' ) , { '__name__' : "__main__" , '__file__' : "setup.py" , '__f8r_setup' : setup , } ) except Exception as e : LOG . exception ( "Couldn't evaluate setup.py: %s" , e ) sys . path . pop ( 0 )
Initialize package setup visitor.