Skip to content

Enforce basic PEP8 style with TravisCI #840

Closed

Description

@peterjc

See also #493 for using a git pre-commit hook.

I would like to have the git pre-commit hook be quite strict, requiring explicit by-passing with --no-verify on a case by case basis, while the TravisCI check should be less onerous but mandatory. Right now something like this in .travis.yml could work:

 - pip install pep8
 - pep8 --ignore E123,E126,E128,E501 BioSQL/
 - pep8 --ignore E123,E126,E127,E128,E402,E501 Scripts/
 - pep8 --ignore E127,E128,E501 Doc/examples/
 - pep8 --ignore E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E231,E241,E302,E402,E501,E731,W291,W293,W391,W503 Bio/

I have no particular preference over using the command line tool pep8 versus flake8 or anything else - whatever is quickest would be practical if they check the same things.

Medium term I'd like us to work towards removing as many of these PEP8 violations as possible and make the TravisCI checking stricter over time.

This adds about 20 to 25s to the TravisCI run, but only really needs to be done once rather than for every version of Python (possibly twice for Python 2 and Python 3?). An alternative might by combining TravisCI with Tox along the lines used in https://github.com/galaxyproject/planemo/blob/master/.travis.yml and https://github.com/galaxyproject/planemo/blob/master/tox.ini

Activity

  1. peterjc commented on Jun 6, 2016

    @peterjc
    MemberAuthor

    For comparison, the pre-commit hook currently uses:

    pep8 --ignore E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E501 [files]
    

    All the E402 module level import not at top of file violations under Scripts/ are from Scripts/xbbtools/ which I would like to deprecate and remove (edit: see #848)

  2. peterjc commented on Jun 9, 2016

    @peterjc
    MemberAuthor
  3. peterjc commented on Jun 9, 2016

    @peterjc
    MemberAuthor

    Progress: 54212c7 9e4967c a973b78 92b4d0e 9866882 450824d

    The main code base now only needs:

    $ pep8 --ignore E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E501,W291,E731 Bio/
    

    We have quite a lot of code breaking E731 by using lambda functions.

    However, only two files are failing W291 trailing whitespace, Bio/AlignIO/NexusIO.py (which also falls under #820) and Bio/SeqUtils/__init__.py which is a little trickier.

    The tests need more work though, lots of PEP8 white space violations etc.

  4. peterjc commented on Jun 13, 2016

    @peterjc
    MemberAuthor

    Progress on the tests with 0daf209 and fe49ffa - now only need to ignore:

    $ pep8 --ignore E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E402,E501,W191,W291,W293,E101,E241,E721,E731 Tests/
    

    Note many of the tab/white space issues here are from embedded sample data files:

  5. cbrueffer commented on Jul 7, 2016

    @cbrueffer
    Member

    I like this (obviously) and think we should enable this sooner rather than later, before instances of the already eliminated classes creep back into the repo. We can always shorten the ignore list as we go.

  6. bow commented on Jul 21, 2016

    @bow
    Member

    Hi @peterjc,

    This looks great; 20-25s seems like a worthwhile trade off if we can enforce a common style across the library :).

    One small suggestion / thing to check is on the use of setup.cfg or .pep8 for storing the PEP8 preferences (which errors to ignore, etc.). AFAIK, it's not only pep8 reads the setup.cfg or .pep8, but some editors which has a pep8 check can use this file as well. Which means the style check of the editor will be the same as what Biopython has.

    What I'm not sure about is whether this works for multiple directories, since the traditional setup is to have a single setup.cfg with a single preference set (while we have multiple preference sets, I see).

  7. peterjc commented on Jul 22, 2016

    @peterjc
    MemberAuthor

    The reason I have implemented this with different ignore lists for the different folders is practicality - long term I'd like all the folders to obey the same agreed set of coding styles, but right now some parts of the code is more compliant than others.

    According to http://pep8.readthedocs.io/en/release-1.7.x/intro.html#configuration we could also use tox.ini but as written this pull request deliberately ignores this naming:

    At the project level, a setup.cfg file or a tox.ini file is read if present (.pep8 file is also supported, but it is deprecated). If none of these files have a [pep8] section, no project specific configuration is loaded.

    Given a bit more work so we can use a single pep8 configuration this would be a very good idea @bow 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions