pyflakes will be a part of Leo

71 views
Skip to first unread message

Edward K. Ream

unread,
Mar 3, 2013, 8:31:10 AM3/3/13
to leo-e...@googlegroups.com
pyflakes https://pypi.python.org/pypi/pyflakes is like pylint, but 10 times faster.  This creates a new opportunity: Leo should have an option to run pyflakes on all dirty @file nodes when saving a .leo file.

pyflakes is a breath of fresh air.  The code is much simpler than its fantastically complex "competitors", including my stc project!  I have found it easy to change the pyflakes code.

Yesterday I wrote a Leo script to drive pyflakes on Leo files.  As of rev 341, this script is in the stc project in the node "@test *local* pyflakes".  This node contains a repacking of all the classes in pyflakes.  I will soon cut and paste this node into scripts.leo.

I used this script to remove all the "flakes" from Leo's core files.  This revealed two true bugs in Leo.  I found only one bug in pyflakes--pyflakes generates an erroneous flake for::

    dn = self.def_stack[-1]
    dn.code += s

pyflakes says that dn isn't used after being defined! Happily, no flake appears for::

    self.def_stack[-1].code += s

It will be easy to integrate pyflakes into Leo (see below), but I want to investigate pyflakes in more detail first...

Edward

P.S. I made the following changes to a local copy of pyflakes in the stc project:

Repackaged all the pyflakes classes so they could be used by the Leo script.  This was remarkably easy to do.

The Reporter class now funnels all its output to the new r.write method.  This method does nothing if the output stream is None.  This allows timing runs that ignore the time taken to print flakes.  For Leo, r.write might create a gui table that will take you to the proper place in the source code if you click one of the rows.  Iirc, Kent has asked for something like this when Leo reports syntax errors in the code.

Changed runFunction (a helper function in the Checker class) so that pyflakes doesn't complain about unused vars for vars whose names start with 'unused' or 'junk'.

Changed Message.__repr__ so that it uses short file names when the global ekr switch is true.  This makes flakes much easier to read.  The Leo driver script reports enough context so that these shorter flakes suffice.

Rev 341 also contains the "@test pyflakes unit tests" driver that runs all the pyflakes unit tests on (possibly modified) code in python/Lib/site-packages. Many unit tests depend on Message.__repr__: they will fail if ekr is True. As I write this, I see that the solution will be to add a new argument to the Message ctor.  m.__repr__ can use this arg to determine whether it is being called in a unit test.

EKR

HaveF

unread,
Mar 3, 2013, 10:17:04 AM3/3/13
to Leo-editor-googlegroup
Yesterday, I just notice pyflakes also as a recommend contributing tool for sklearn(a python machine learning toolbox).
"""

You can also check for common programming errors with the following tools:

  • Code with a good unittest coverage (at least 90%, better 100%), check with:

    $ pip install nose coverage
    $ nosetests --with-coverage path/to/tests_for_package

    see also Testing and improving test coverage

  • No pyflakes warnings, check with:

    
    $ pip install pyflakes
    $ pyflakes path/to/module.py
  • No PEP8 warnings, check with:

    
    $ pip install pep8
    $ pep8 path/to/module.py
  • AutoPEP8 can help you fix some of the easy redundant errors:

    $ pip install autopep8
    $ autopep8 path/to/pep8.py

"""




EKR

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
To post to this group, send email to leo-e...@googlegroups.com.
Visit this group at http://groups.google.com/group/leo-editor?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
--
Sincerely,

HaveF

Jacob Peck

unread,
Mar 4, 2013, 9:56:12 AM3/4/13
to leo-e...@googlegroups.com
Not to derail, but have you seen flake8
(https://pypi.python.org/pypi/flake8)? It combines pyflakes with pep8,
and a few other checks.

-->Jake

Edward K. Ream

unread,
Mar 6, 2013, 5:26:27 PM3/6/13
to leo-e...@googlegroups.com
On Mon, Mar 4, 2013 at 8:56 AM, Jacob Peck <gates...@gmail.com> wrote:
Not to derail, but have you seen flake8 (https://pypi.python.org/pypi/flake8)? It combines pyflakes with pep8, and a few other checks.

Thanks for this link, and the previous links.  When I mentioned pyflakes earlier I really mean "some quick checks".  I've been exploring pyflakes, but other quick checking tools might be good.  I have some ideas for extending pyflakes with attribute checks...

Imo, everything connected to pep 8 should be optional.  Yes, in some situations pep 8 compliance is important, but pep 8 non-compliance can not, by itself, create bugs.  Leo should have pep 8 tools that run, as usual, via emacs-like commands.

Edward
Reply all
Reply to author
Forward
0 new messages