Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce basic PEP8 style with a pre-commit git hook #493

Closed
peterjc opened this issue Mar 25, 2015 · 10 comments
Closed

Enforce basic PEP8 style with a pre-commit git hook #493

peterjc opened this issue Mar 25, 2015 · 10 comments

Comments

@peterjc
Copy link
Member

peterjc commented Mar 25, 2015

See discussion on #406 and on the mailing list (e.g. http://mailman.open-bio.org/pipermail/biopython-dev/2014-October/020741.html ) where @cbrueffer proposed adopting this pre-commit git hook: https://github.com/cbrueffer/pep8-git-hook

I've been using this on Mac and Linux and it works very nicely.

Before adopting this we need to test it under Windows, where we need to know if it works, safely has no effect, or causes problems.

@peterjc
Copy link
Member Author

peterjc commented Oct 14, 2015

I've since learnt that we can't enforce a git hook within the repository itself (which surprised me as things like .gitignore work that way). All we can do is document this (e.g. some projects bundle their pre-commit hook as a script in the repository and include a make command to install it).

peterjc added a commit to peterjc/biopython that referenced this issue Jun 3, 2016
Currently I've had to ignore losts of PEP8 codes given the current
state of the codebase - the goal would be to clean this up (see
also the stricter pre-commit hook we've been using as per
GitHub issue biopython#493.
peterjc added a commit that referenced this issue Jun 13, 2016
Can now use this without errors, see GitHub issues #493 and #840:

$ pep8 --select W291 Bio/ BioSQL/ Tests/ Scripts/ Doc/
MarkusPiotrowski pushed a commit to MarkusPiotrowski/biopython that referenced this issue Jun 15, 2016
Can now use this without errors, see GitHub issues biopython#493 and biopython#840:

$ pep8 --select W291 Bio/ BioSQL/ Tests/ Scripts/ Doc/
@peterjc
Copy link
Member Author

peterjc commented Jul 21, 2016

Comment from @MarkusPiotrowski on the mailing list:

Regarding Windows: I'm using Git for Windows and flake8 as pre-commit
hook which can easily be setup by flake8 itself:
$ flake8 --install-hook=git

http://lists.open-bio.org/pipermail/biopython-dev/2016-July/021468.html

This is very simple to install, although likely to be quite verbose and complain about many things already in Biopython (like our legacy mixed case module names).

@peterjc
Copy link
Member Author

peterjc commented Feb 23, 2017

Thinking about this again, I think we should do something like this:

  1. Create new file called Scripts/git_pre_commit_hook.py or similar (it could be written in bash?) within our repository
  2. Provide instructions to set this up as a your pre-commit hook, cd biopython and run ln -s Scripts/git_pre_commit_hook.py .git/hooks/pre-commit

The new script would ideally cover not just the command line tool pep8, but also flake8, pydocstyle (for PEP257 docstrings) and eventually rst-lint as well - covering the same core set of checks as our TravisCI/Tox setup. Indeed, depending on how we resolve #883, the TravisCI/Tox setup might be implemented by calling the same script but with an option to check all the files not just the changed files?

@peterjc
Copy link
Member Author

peterjc commented Feb 24, 2017

Work in progress here which runs flake8 etc and rst-lint (planned for the TravisCI/Tox setup soon):

https://github.com/peterjc/biopython/blob/pre_commit_linting/Scripts/git_pre_commit_hook.py

@peterjc
Copy link
Member Author

peterjc commented Apr 24, 2017

I've updated the hook on my branch which runs flake8 and rst-lint to use the same configuration as our TravisCI/Tox setup - i.e. read the .flake8 and .pydocstyle files:

https://github.com/peterjc/biopython/blob/pre_commit_linting/Scripts/git_pre_commit_hook.py

This makes it much simpler to explain to a new-comer what is going on with the TravisCI tests vs the git hook, which is a plus.

I still like the idea of the git hook being stricter, but making them the same seems more practical. And over time we'll hopefully cleanup the back-log of style violations anyway.

@cbrueffer
Copy link
Member

Nice, this is quite a step forward from the previous hook! I think whether TravisCI/local check have the same settings or local is stricter doesn't make much of a difference, so the current choice seems fine.

@peterjc
Copy link
Member Author

peterjc commented Jun 21, 2017

I've been thinking (now that we run pydocstyle via its flake8 plugin) that using the flake8 hook might be simpler, although its default settings are not suitable so we'd need to recommend something like:

$ pip install flake8 flake8-docstrings flake8-blind-except
$ flake8 --install-hook git
$ git config --bool flake8.strict true

Personally, I set the configuration globally rather than just on the current repository. See: http://flake8.pycqa.org/en/latest/user/using-hooks.html

The downside is this would only check the Python files, and not the *.rst files or anything else. However, we don't have to maintain our own custom script - which is a big plus.

@peterjc
Copy link
Member Author

peterjc commented Aug 4, 2017

As per my last comment, I was hoping we might be able to use the default flake8 pre-commit hook. However, right now that does not work well with per-folder .flake8 settings files: https://gitlab.com/pycqa/flake8/issues/360

Update: See flake8 feature request https://gitlab.com/pycqa/flake8/issues/347 to support directory/file level ignores in project configuration file

MarkusPiotrowski pushed a commit to MarkusPiotrowski/biopython that referenced this issue Oct 31, 2017
Can now use this without errors, see GitHub issues biopython#493 and biopython#840:

$ pep8 --select W291 Bio/ BioSQL/ Tests/ Scripts/ Doc/
@peterjc
Copy link
Member Author

peterjc commented Apr 18, 2019

My comment here #2014 (comment) was probably better on the original issue.

@peterjc
Copy link
Member Author

peterjc commented May 24, 2019

Flake8 pre-commit hook documented as of #2075.

@peterjc peterjc closed this as completed May 24, 2019
victorlin pushed a commit to victorlin/biopython that referenced this issue May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants