Ejemplo n.º 1
0
    def _boundedReformatBlocks(self, block, endPosition,
                               forceHighlightOfNextBlock):
        '''Reformat at most self.n_max_lines blocks.
        Queue _idleReformatBlocks if more blocks remain.'''

        trace = False and not g.unitTesting
        trace_block = False
        trace_delay = True
        trace_end = True
        count = 0
        generation = self.generation
        while True:
            if (block and block.isValid()
                    and (block.position() < endPosition
                         or forceHighlightOfNextBlock or self.recolorAll)):
                self.bounded_reformat_count += 1
                if trace and trace_block:
                    g.trace('%4s block: %s' %
                            (self.bounded_reformat_count, id(block)))
                stateBeforeHighlight = block.userState()
                self._reformatBlock(block)
                forceHighlightOfNextBlock = block.userState(
                ) != stateBeforeHighlight
                block = block.next()
                count += 1
                if count > self.max_lines:
                    # g.app.gui.qtApp.processEvents();
                    # if self.generation != generation:
                    # if trace: g.trace('interrupt')
                    # return
                    if block and block.isValid():
                        if trace and trace_delay:
                            g.trace('delay %4s %s' %
                                    (self.bounded_reformat_count,
                                     g.timeSince(self.t1)))
                        self.delayedBlock = block
                        self.delayedForceHighlight = forceHighlightOfNextBlock
                        self.delayedEndPosition = endPosition
                        Qt.QTimer.singleShot(self.delay,
                                             self._idleReformatBlocks)
                    break
            else:
                self.recolorAll = False
                if trace and trace_end:
                    g.trace(
                        '*done %4s %s' %
                        (self.bounded_reformat_count, g.timeSince(self.t1)))
                # if self.interruptedFlag:
                # self.interruptedFlag = False
                # if trace and trace_end: g.trace('redoing all highlighting')
                # Qt.QTimer.singleShot(1000,self.base_rehighlight)
                break
        self.formatChanges = []
Ejemplo n.º 2
0
 def run(self):
     '''Run Pylint on all Python @<file> nodes in c.p's tree.'''
     c, root = self.c, self.c.p
     rc_fn = self.get_rc_file()
     if not rc_fn:
         return
     # Make sure Leo is on sys.path.
     leo_path = g.os_path_finalize_join(g.app.loadDir, '..')
     if leo_path not in sys.path:
         sys.path.append(leo_path)
     # Run lint on all Python @<file> nodes in root's tree.
     t1 = time.time()
     found = False
     for p in root.self_and_subtree():
         found |= self.check(p, rc_fn)
     # Look up the tree if no @<file> nodes were found.
     if not found:
         for p in root.parents():
             if self.check(p, rc_fn):
                 found = True
                 break
     # If still not found, expand the search if root is a clone.
     if not found:
         isCloned = any([p.isCloned() for p in root.self_and_parents()])
         # g.trace(isCloned,root.h)
         if isCloned:
             for p in c.all_positions():
                 if p.isAnyAtFileNode():
                     isAncestor = any(
                         [z.v == root.v for z in p.self_and_subtree()])
                     # g.trace(isAncestor,p.h)
                     if isAncestor and self.check(p, rc_fn):
                         break
     if self.wait:
         g.es_print('pylint done %s' % g.timeSince(t1))
Ejemplo n.º 3
0
    def run(self, p=None, force=False, pyflakes_errors_only=False):
        '''Run Pyflakes on all Python @<file> nodes in c.p's tree.'''
        c = self.c
        root = p or c.p
        # Make sure Leo is on sys.path.
        leo_path = g.os_path_finalize_join(g.app.loadDir, '..')
        if leo_path not in sys.path:
            sys.path.append(leo_path)
        t1 = time.time()

        def predicate(p):
            return p.isAnyAtFileNode() and p.h.strip().endswith('.py')

        roots = g.findRootsWithPredicate(c, root, predicate)
        if root:
            paths = [self.finalize(z) for z in roots]
            # These messages are important for clarity.
            log_flag = not force
            total_errors = self.check_all(log_flag, paths,
                                          pyflakes_errors_only)
            if total_errors > 0:
                g.es('ERROR: pyflakes: %s error%s' %
                     (total_errors, g.plural(total_errors)))
            elif force:
                g.es('OK: pyflakes: %s file%s in %s' %
                     (len(paths), g.plural(paths), g.timeSince(t1)))
            elif not pyflakes_errors_only:
                g.es('OK: pyflakes')
            ok = total_errors == 0
        else:
            ok = True
        return ok
Ejemplo n.º 4
0
 def run(self, p=None):
     '''Run flake8 on all Python @<file> nodes in c.p's tree.'''
     c = self.c
     root = p or c.p
     # Make sure Leo is on sys.path.
     leo_path = g.os_path_finalize_join(g.app.loadDir, '..')
     if leo_path not in sys.path:
         sys.path.append(leo_path)
     # Run flake8 on all Python @<file> nodes in root's tree.
     t1 = time.time()
     found = False
     for p in root.self_and_subtree():
         found |= self.find(p)
     # Look up the tree if no @<file> nodes were found.
     if not found:
         for p in root.parents():
             if self.find(p):
                 found = True
                 break
     # If still not found, expand the search if root is a clone.
     if not found:
         isCloned = any([p.isCloned() for p in root.self_and_parents()])
         # g.trace(isCloned,root.h)
         if isCloned:
             for p in c.all_positions():
                 if p.isAnyAtFileNode():
                     isAncestor = any([z.v == root.v for z in p.self_and_subtree()])
                     # g.trace(isAncestor,p.h)
                     if isAncestor and self.find(p):
                         break
     paths = list(set(self.seen))
     if paths:
         self.check_all(paths)
     g.es_print('flake8: %s file%s in %s' % (
         len(paths), g.plural(paths), g.timeSince(t1)))
Ejemplo n.º 5
0
 def run(self, p=None, force=False, pyflakes_errors_only=False):
     '''Run Pyflakes on all Python @<file> nodes in c.p's tree.'''
     c = self.c
     root = p or c.p
     # Make sure Leo is on sys.path.
     leo_path = g.os_path_finalize_join(g.app.loadDir, '..')
     if leo_path not in sys.path:
         sys.path.append(leo_path)
     t1 = time.time()
     roots = g.findRootsWithPredicate(c, root, predicate=None)
     if root:
         paths = [self.finalize(z) for z in roots]
         # These messages are important for clarity.
         log_flag = not force
         total_errors = self.check_all(log_flag, paths, pyflakes_errors_only, roots=roots)
         if total_errors > 0:
             g.es('ERROR: pyflakes: %s error%s' % (
                 total_errors, g.plural(total_errors)))
         elif force:
             g.es('OK: pyflakes: %s file%s in %s' % (
                 len(paths), g.plural(paths), g.timeSince(t1)))
         elif not pyflakes_errors_only:
             g.es('OK: pyflakes')
         ok = total_errors == 0
     else:
         ok = True
     return ok
Ejemplo n.º 6
0
 def run(self, p=None):
     '''Run flake8 on all Python @<file> nodes in c.p's tree.'''
     c = self.c
     root = p or c.p
     # Make sure Leo is on sys.path.
     leo_path = g.os_path_finalize_join(g.app.loadDir, '..')
     if leo_path not in sys.path:
         sys.path.append(leo_path)
     # Run flake8 on all Python @<file> nodes in root's tree.
     t1 = time.time()
     found = False
     for p in root.self_and_subtree():
         found |= self.find(p)
     # Look up the tree if no @<file> nodes were found.
     if not found:
         for p in root.parents():
             if self.find(p):
                 found = True
                 break
     # If still not found, expand the search if root is a clone.
     if not found:
         isCloned = any([p.isCloned() for p in root.self_and_parents()])
         # g.trace(isCloned,root.h)
         if isCloned:
             for p in c.all_positions():
                 if p.isAnyAtFileNode():
                     isAncestor = any([z.v == root.v for z in p.self_and_subtree()])
                     # g.trace(isAncestor,p.h)
                     if isAncestor and self.find(p):
                         break
     paths = list(set(self.seen))
     if paths:
         self.check_all(paths)
     g.es_print('flake8: %s file%s in %s' % (
         len(paths), g.plural(paths), g.timeSince(t1)))
Ejemplo n.º 7
0
 def run(self):
     '''Run Pylint on all Python @<file> nodes in c.p's tree.'''
     c, root = self.c, self.c.p
     rc_fn = self.get_rc_file()
     if not rc_fn:
         return
     # Make sure Leo is on sys.path.
     leo_path = g.os_path_finalize_join(g.app.loadDir, '..')
     if leo_path not in sys.path:
         sys.path.append(leo_path)
     # Run lint on all Python @<file> nodes in root's tree.
     t1 = time.time()
     found = False
     for p in root.self_and_subtree():
         found |= self.check(p, rc_fn)
     # Look up the tree if no @<file> nodes were found.
     if not found:
         for p in root.parents():
             if self.check(p, rc_fn):
                 found = True
                 break
     # If still not found, expand the search if root is a clone.
     if not found:
         isCloned = any([p.isCloned() for p in root.self_and_parents()])
         # g.trace(isCloned,root.h)
         if isCloned:
             for p in c.all_positions():
                 if p.isAnyAtFileNode():
                     isAncestor = any([z.v == root.v for z in p.self_and_subtree()])
                     # g.trace(isAncestor,p.h)
                     if isAncestor and self.check(p, rc_fn):
                         break
     if self.wait:
         g.es_print('pylint done %s' % g.timeSince(t1))
Ejemplo n.º 8
0
    def _boundedReformatBlocks(self,block,endPosition,forceHighlightOfNextBlock):
        
        '''Reformat at most self.n_max_lines blocks.
        Queue _idleReformatBlocks if more blocks remain.'''

        trace = False and not g.unitTesting
        trace_block = False ; trace_delay = True ; trace_end = True
        count = 0
        generation = self.generation
        while True:
            if (block and block.isValid() and (
                    block.position() < endPosition or
                    forceHighlightOfNextBlock or
                    self.recolorAll)
            ):
                self.bounded_reformat_count += 1
                if trace and trace_block: g.trace('%4s block: %s' % (
                    self.bounded_reformat_count,id(block)))
                stateBeforeHighlight = block.userState()
                self._reformatBlock(block)
                forceHighlightOfNextBlock = block.userState() != stateBeforeHighlight
                block = block.next()
                count += 1
                if count > self.max_lines:
                    # g.app.gui.qtApp.processEvents();
                    # if self.generation != generation:
                        # if trace: g.trace('interrupt')
                        # return
                    if block and block.isValid():
                        if trace and trace_delay: g.trace('delay %4s %s' % (
                            self.bounded_reformat_count,g.timeSince(self.t1)))
                        self.delayedBlock = block
                        self.delayedForceHighlight = forceHighlightOfNextBlock
                        self.delayedEndPosition = endPosition
                        Qt.QTimer.singleShot(self.delay,self._idleReformatBlocks)
                    break
            else:
                self.recolorAll = False
                if trace and trace_end: g.trace('*done %4s %s' % (
                    self.bounded_reformat_count,g.timeSince(self.t1)))
                # if self.interruptedFlag:
                    # self.interruptedFlag = False
                    # if trace and trace_end: g.trace('redoing all highlighting')
                    # Qt.QTimer.singleShot(1000,self.base_rehighlight)
                break
        self.formatChanges = []
Ejemplo n.º 9
0
def main(tables_table):
    
    if tables_table and sys.platform.startswith('win'):
        if False and scope != 'file':
            g.cls()
    # Do these imports **after** clearing the screen.
    from pylint import lint
        # in pythonN/Lib/site-packages.
    t1 = time.clock()
    for table,theDir in tables_table:
        for fn in table:
            run(theDir,fn)
    print('time: %s' % g.timeSince(t1))
    def full_redraw (self,p=None,scroll=True,forceDraw=False):

        '''Redraw all visible nodes of the tree.

        Preserve the vertical scrolling unless scroll is True.'''

        trace = False and not g.app.unitTesting
        verbose = False
        c = self.c

        if g.app.disable_redraw:
            if trace: g.trace('*** disabled',g.callers())
            return

        if self.busy():
            return g.trace('*** full_redraw: busy!',g.callers())

        if p is None:
            p = c.currentPosition()
        elif c.hoistStack and len(c.hoistStack) == 1 and p.h.startswith('@chapter') and p.hasChildren():
            # Make sure the current position is visible.
            # Part of fix of bug 875323: Hoist an @chapter node leaves a non-visible node selected.
            p = p.firstChild()
            if trace: g.trace('selecting',p.h)
            c.frame.tree.select(p)
            c.setCurrentPosition(p)
        else:
            c.setCurrentPosition(p)

        self.redrawCount += 1
        if trace: t1 = g.getTime()
        self.initData()
        self.nodeDrawCount = 0
        try:
            self.redrawing = True
            self.drawTopTree(p)
        finally:
            self.redrawing = False

        self.setItemForCurrentPosition(scroll=scroll)
        c.requestRedrawFlag= False

        if trace:
            theTime = g.timeSince(t1)
            g.trace('*** %s: scroll %5s drew %3s nodes in %s' % (
                self.redrawCount,scroll,self.nodeDrawCount,theTime),g.callers())

        return p # Return the position, which may have changed.
Ejemplo n.º 11
0
    def full_redraw (self,p=None,scroll=True,forceDraw=False):

        '''Redraw all visible nodes of the tree.

        Preserve the vertical scrolling unless scroll is True.'''

        trace = False and not g.app.unitTesting
        verbose = False
        c = self.c
        
        if g.app.disable_redraw:
            if trace: g.trace('*** disabled',g.callers())
            return

        if self.busy():
            return g.trace('*** full_redraw: busy!',g.callers())

        if p is None:
            p = c.currentPosition()
        elif c.hoistStack and len(c.hoistStack) == 1 and p.h.startswith('@chapter') and p.hasChildren():
            # Make sure the current position is visible.
            # Part of fix of bug 875323: Hoist an @chapter node leaves a non-visible node selected.
            p = p.firstChild()
            if trace: g.trace('selecting',p.h)
            c.frame.tree.select(p)
            c.setCurrentPosition(p)
        else:
            c.setCurrentPosition(p)

        self.redrawCount += 1
        if trace: t1 = g.getTime()
        self.initData()
        self.nodeDrawCount = 0
        try:
            self.redrawing = True
            self.drawTopTree(p)
        finally:
            self.redrawing = False

        self.setItemForCurrentPosition(scroll=scroll)
        c.requestRedrawFlag= False

        if trace:
            theTime = g.timeSince(t1)
            g.trace('*** %s: scroll %5s drew %3s nodes in %s' % (
                self.redrawCount,scroll,self.nodeDrawCount,theTime),g.callers())
                
        return p # Return the position, which may have changed.
Ejemplo n.º 12
0
 def run(self):
     '''Run Pylint on all Python @<file> nodes in c.p's tree.'''
     c, root = self.c, self.c.p
     rc_fn = self.get_rc_file()
     if not rc_fn:
         return
     # Make sure Leo is on sys.path.
     leo_path = g.os_path_finalize_join(g.app.loadDir, '..')
     if leo_path not in sys.path:
         sys.path.append(leo_path)
     t1 = time.time()
     roots = g.findRootsWithPredicate(c, root, predicate=None)
     for p in roots:
         self.check(p, rc_fn)
     if self.wait:
         g.es_print('pylint done %s' % g.timeSince(t1))
Ejemplo n.º 13
0
 def run(self):
     '''Run Pylint on all Python @<file> nodes in c.p's tree.'''
     c, root = self.c, self.c.p
     rc_fn = self.get_rc_file()
     if not rc_fn:
         return
     # Make sure Leo is on sys.path.
     leo_path = g.os_path_finalize_join(g.app.loadDir, '..')
     if leo_path not in sys.path:
         sys.path.append(leo_path)
     t1 = time.time()
     roots = g.findRootsWithPredicate(c, root, predicate=None)
     for p in roots:
         self.check(p, rc_fn)
     if self.wait:
         g.es_print('pylint done %s' % g.timeSince(t1))
Ejemplo n.º 14
0
 def run(self, p=None, force=False):
     '''Run Pyflakes on all Python @<file> nodes in c.p's tree.'''
     c = self.c
     root = p or c.p
     # Make sure Leo is on sys.path.
     leo_path = g.os_path_finalize_join(g.app.loadDir, '..')
     if leo_path not in sys.path:
         sys.path.append(leo_path)
     # Run pyflakes on all Python @<file> nodes in root's tree.
     t1 = time.time()
     found = False
     for p in root.self_and_subtree():
         found |= self.find(p)
     # Look up the tree if no @<file> nodes were found.
     if not found:
         for p in root.parents():
             if self.find(p):
                 found = True
                 break
     # If still not found, expand the search if root is a clone.
     if not found:
         isCloned = any([p.isCloned() for p in root.self_and_parents()])
         if isCloned:
             for p in c.all_positions():
                 if p.isAnyAtFileNode():
                     isAncestor = any(
                         [z.v == root.v for z in p.self_and_subtree()])
                     if isAncestor and self.find(p):
                         break
     paths = list(set(self.seen))
     if paths:
         # These messages are important for clarity.
         log_flag = not force
         total_errors = self.check_all(log_flag, paths)
         if total_errors > 0:
             g.es('ERROR: pyflakes: %s error%s' %
                  (total_errors, g.plural(total_errors)))
         elif force:
             g.es('OK: pyflakes: %s file%s in %s' %
                  (len(paths), g.plural(paths), g.timeSince(t1)))
         else:
             g.es('OK: pyflakes')
         ok = total_errors == 0
     else:
         ok = True
     return ok
Ejemplo n.º 15
0
 def run(self, p=None, force=False):
     '''Run Pyflakes on all Python @<file> nodes in c.p's tree.'''
     c = self.c
     root = p or c.p
     # Make sure Leo is on sys.path.
     leo_path = g.os_path_finalize_join(g.app.loadDir, '..')
     if leo_path not in sys.path:
         sys.path.append(leo_path)
     # Run pyflakes on all Python @<file> nodes in root's tree.
     t1 = time.time()
     found = False
     for p in root.self_and_subtree():
         found |= self.find(p)
     # Look up the tree if no @<file> nodes were found.
     if not found:
         for p in root.parents():
             if self.find(p):
                 found = True
                 break
     # If still not found, expand the search if root is a clone.
     if not found:
         isCloned = any([p.isCloned() for p in root.self_and_parents()])
         if isCloned:
             for p in c.all_positions():
                 if p.isAnyAtFileNode():
                     isAncestor = any([z.v == root.v for z in p.self_and_subtree()])
                     if isAncestor and self.find(p):
                         break
     paths = list(set(self.seen))
     if paths:
         # These messages are important for clarity.
         log_flag = not force
         total_errors = self.check_all(log_flag, paths)
         if total_errors > 0:
             g.es('ERROR: pyflakes: %s error%s' % (
                 total_errors, g.plural(total_errors)))
         elif force:
             g.es('OK: pyflakes: %s file%s in %s' % (
                 len(paths), g.plural(paths), g.timeSince(t1)))
         else:
             g.es('OK: pyflakes')
         ok = total_errors == 0
     else:
         ok = True
     return ok
Ejemplo n.º 16
0
def main(tables_table):

    if tables_table and sys.platform.startswith('win'):
        if False and scope != 'file':
            g.cls()
            # os.system('cls')

    # Do these imports **after** clearing the screen.
    from pylint import lint
    # in pythonN/Lib/site-packages.

    t1 = time.clock()
    for table, theDir in tables_table:
        for fn in table:
            run(theDir, fn)
    if 0:
        print('astroid.bases.ekr_infer_stmts_items: %s' %
              astroid.bases.ekr_infer_stmts_items)
    print('time: %s' % g.timeSince(t1))
Ejemplo n.º 17
0
def test(c):
    g.cls()
    t1 = time.time()
    RopeController(c).run()
    print('done: %s sec.' % g.timeSince(t1))
Ejemplo n.º 18
0
def test(c):
    g.cls()
    t1 = time.clock()
    RopeController(c).run()
    print('done: %s sec.' % g.timeSince(t1))