Repository: biopython/biopython

Issue:
Enforce basic PEP8 style with TravisCI
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



Discussion:
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)

e.g. 37d926bc33e98b37e8942b2383394790b88c262f 8f9c7e917af86208c73dcead81f69efbf3208149 e1e3e6d7f5df26b9ee013b48b223c624a47bd1cb 9f96c4d92c05858d621cfecda96a746ecaeb34b6 8cd7843cd43cfc2fb2669ebc593240fa7812c03d

Progress: 54212c741106e3735a606085196ef16d674bfb83 9e4967c492172db4be49f0d622bf393157a6c341 a973b783232d4c0d0202d2718a8549aeb0e635b0 92b4d0e585658d18d6580ef6a3f7a049011ea8e7 98668823651d2d6405b7f91ae7a363ad63065e26 450824d0e63d481e56c96b6b0cdf89259554eb9f

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.

Progress on the tests with 0daf2094b9969bca80e576a77e30285e30344165 and fe49ffab20239778c76a53d33b6f90a971bbd827 - 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:

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.

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](https://github.com/PyCQA/pycodestyle/issues/93), 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).

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 👍 


Resolving patch:
diff --git a/Bio/PDB/DSSP.py b/Bio/PDB/DSSP.py
--- a/Bio/PDB/DSSP.py
+++ b/Bio/PDB/DSSP.py
@@ -285,7 +285,7 @@ def __init__(self, model, pdb_file, dssp="dssp", acc_array="Sander"):
         """
 
         self.residue_max_acc = residue_max_acc[acc_array]
-        
+
         # create DSSP dictionary
         dssp_dict, dssp_keys = dssp_dict_from_pdb_file(pdb_file, dssp)
         dssp_map = {}


Test patch: