[Biopython-dev] Status & scope of the git pre-commit hook?

Peter Cock p.j.a.cock at googlemail.com
Thu Dec 15 16:19:31 UTC 2016


Hi Adam,

TL;DR - we have some gaps in our developer facing
documentation, but most of what you want is possible.

On Mon, Dec 12, 2016 at 12:46 PM, Adam Kurkiewicz <popantrop at gmail.com> wrote:
> What is the status and the scope of the git pre-commit
> hook in biopython?

It works as described on
https://github.com/biopython/biopython/issues/493

I like it and would like to encourage all our developers and
contributors to use it - but since you can't add this directly
to the git repository settings, it has to be a documentation
issue where we tell people to do it.

Since turning on PEP8 checking with TravisCI this is more
important, thus issue 883.

> I found an issue raised here, but I can't tell if this is work in
> progress or something accomplished:
> https://github.com/biopython/biopython/issues/883.

That's a wider issue about the TravisCI/Tox/PEP8 linting
settings and how to make them more accessible (e.g.
for your exact use case).

> I couldn't find the hook in the project files.

See https://github.com/biopython/biopython/issues/493

> Ideally, what I'm looking for is a code snippet, which will:
>
> - run test cases for the files I changed since the last commit (not
> all the files -- too slow).

Nearly impossible? The internal dependencies of Biopython
would make that quite a challenge. But perhaps someone
has already solved this my inspecting the imports of each
test file, and the import dependencies themselves?

> - run pep8 on the files I changed since the last commit (not all the
> files -- too slow).

Easy - that's what the recommend git pre-commit hook does.

> - run itself automatically before committing, but also allow me to run
> it manually.

Running the hook script explicitly would do that, e.g.

.git/hooks/pre-commit

> The motivation is to cut down on the time spent waiting for test cases
> to pass every time I do some work on the codebase, and to prevent me
> from committing invalid code.

Exactly :)

> I've eventually (poorly) written one myself (based on a snippet passed
> by Peter), which is suitable for what I'm doing with biopython just
> now:
>
>     #!/bin/sh
>     set -xe
>     unset PYTHONPATH
>
>     # these are hard coded, which isn't nice:
>     python2 Tests/run_tests.py test_Affy test_CelFile Bio.Affy Bio.Affy.CelFile
>     python3 Tests/run_tests.py test_Affy test_CelFile Bio.Affy Bio.Affy.CelFile
>     pypy Tests/run_tests.py test_Affy test_CelFile Bio.Affy Bio.Affy.CelFile
>
>     # these should not be so generic (just check the files I changed,
> not all the files!)
>     # Checking all the files is very slow (20+ seconds on my system)
>     pep8 --max-line-length 92 BioSQL/
>     pep8 --ignore E402 --max-line-length 90 Scripts/
>     pep8 --max-line-length 90 Doc/examples/
>     pep8 --ignore E122,E123,E126,E127,E128,E129,E501,E731 Bio/
>     pep8 --ignore E122,E123,E126,E127,E128,E241,E402,E501,E731 Tests/
>
> Before writing this script I've tried installing tox locally, but that
> didn't go very well and I gave up. Also, it doesn't seem that running
> tox would achieve what I want -- a lightweight way to run relevant
> testcases and lint relevant files.

Tox does try to solve most of what you're doing. but would need
to be combined with the magic that the git-commit hook uses
to know which files have changed for linting. That is possible
with clever configuration of the commands we tell tox to run
(using the same approach as the hook uses).

(As noted above, running only tests of interest is very hard)

> I've also tried running a full test suite, but it takes too much time
> to be run regularly.
>
> Adam

What I do is work on feature branches, using the pre-commit
hook, and test at least the modules I expect to be affected locally.
Then I push to GitHub and because I have TravisCI setup on
my personal account too, and that runs the (offline) full test
suite on multiple versions of Python. It does take a while,
but if that works it would work on a pull request (or direct
commit to the master branch).

Adding a summary of your use case to #883 would be great,
as would pull requests to the relevant documentation:

https://github.com/biopython/biopython/blob/master/Doc/Tutorial/chapter_testing.tex

https://github.com/biopython/biopython.github.io/blob/master/wiki/Contributing.md

I'm on leave at the moment (and ought to be asleep right now),
so I won't tackle this myself immediately, but I am still trying to
review pull requests.

Thanks!

Peter


More information about the Biopython-dev mailing list