You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enforce basic PEP8 style with a pre-commit git hook #493
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).
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).
Thinking about this again, I think we should do something like this:
Create new file called Scripts/git_pre_commit_hook.py or similar (it could be written in bash?) within our repository
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?
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:
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.
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.
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:
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.
Activity
Remove redundant string operators; PEP8 whitespace
Added Functionality for Parsing XML Schema Type Files
modified KEGG to add more functionalities in interdatabase id conversion
peterjc commentedon 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
.gitignorework 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).Run pep8 checking as part of TravisCI
White-list test data with trailing whitespaces
White-list test data with trailing whitespaces
peterjc commentedon Jul 21, 2016
Comment from @MarkusPiotrowski on the mailing list:
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 commentedon Feb 23, 2017
Thinking about this again, I think we should do something like this:
Scripts/git_pre_commit_hook.pyor similar (it could be written in bash?) within our repositorycd biopythonand runln -s Scripts/git_pre_commit_hook.py .git/hooks/pre-commitThe new script would ideally cover not just the command line tool
pep8, but alsoflake8,pydocstyle(for PEP257 docstrings) and eventuallyrst-lintas 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 commentedon 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 commentedon Apr 24, 2017
I've updated the hook on my branch which runs
flake8andrst-lintto use the same configuration as our TravisCI/Tox setup - i.e. read the.flake8and.pydocstylefiles: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 commentedon Apr 24, 2017
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 commentedon Jun 21, 2017
I've been thinking (now that we run
pydocstylevia itsflake8plugin) that using theflake8hook might be simpler, although its default settings are not suitable so we'd need to recommend something like: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
*.rstfiles or anything else. However, we don't have to maintain our own custom script - which is a big plus.peterjc commentedon Aug 4, 2017
As per my last comment, I was hoping we might be able to use the default
flake8pre-commit hook. However, right now that does not work well with per-folder.flake8settings files: https://gitlab.com/pycqa/flake8/issues/360Update: See flake8 feature request https://gitlab.com/pycqa/flake8/issues/347 to support directory/file level ignores in project configuration file
White-list test data with trailing whitespaces
peterjc commentedon Apr 18, 2019
My comment here #2014 (comment) was probably better on the original issue.
Update contributing for single .flake8 file
Update contributing for single .flake8 file
peterjc commentedon May 24, 2019
Flake8 pre-commit hook documented as of #2075.
Update contributing for single .flake8 file