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
Emphasize more strongly that contributors should use pre-commit hooks #2014
While Biopython is enforcing many/most coding-style conventions described in PEP-8 and PEP-257, many pull requests get delayed, because contributors (often unintentionally) violate these style conventions.
A discussion about a Biopython specific pre-commit git hook to enforce PEP-8 style has already started some time ago (e.g. #493, #1188).
Using a pre-commit hook in the git environment is an easy way to make contributors aware of style-violations and give them the chance to address these before submitting a pull request.
However, it seems that many contributors are not using pre-commit hooks, and one reason for this may be that they are not aware of them and/because we are not explicit enough about that they should be used.
There are some places, where we could emphasize this more strongly:
README.rst should contain, under 'Contributing', a link to CONTRIBUTING.rst.
CONTRIBUTING.rst should strongly recommend the use of a pre-commit hook and show how to install and set it up.
There should be a clear recommendation, which tools should be used.
This is a very good idea in principle, but the complexities of our different .flake8 settings in different folders is an annoyance requiring the bespoke git pre-commit script.
I would very much like to address that first, which bring the enormous advantage of letting us use an off-the shelf widely used hook, e.g. that provided by flake8 itself:
This looks doable (and is part of my motivation with adopting the black formatting tool, #2008, which would take care of some of these). [Update 22 April: Actually black does not help much, other than E241, which autopep8 can do, we've already fixed all the flake8 style issues black would have handled]
Basically we need to fix a few things in the tests and/or relax the other tests a little.
Pull requests opened to fix D300, D200 and D204 in Tests - a bit more effort on this and we can have a single .flake8 configuration, and use the default flake8 git pre-commit hook - which will be simpler to document and maintain 👍
I propose to solve E731 the pragmatic way - whitelist most of them with #noqa lines, see #2019.
I can fix D100 mostly automatically with the following script (missing docstrings can trigger false edits, and it leaves question marks and exclamation marks to a human to edit), will do this once the current pull requests are merged:
importsysdeffix(lines):
answer= []
post_def=Falseforlineinlines:
ifline.lstrip().startswith("def "):
# print(line.rstrip())post_def=Trueifpost_defandline.lstrip().startswith('"""'):
post_def=False# Looks like line one of a docstringifline.rstrip().endswith('"""'):
# a one-linerifnotline.rstrip().endswith(('."""', '?"""', '!"""')):
print(line.rstrip())
line=line.rstrip()[:-3] +'."""\n'else:
# multi-linerifnotline.rstrip().endswith(('.', '?', '!')):
print(line.rstrip())
line=line.rstrip() +".\n"answer.append(line)
returnanswerforfinsys.argv[1:]:
print(f)
withopen(f) ashandle:
old=list(handle)
new=fix(old)
withopen(f, "w") ashandle:
forlineinnew:
handle.write(line)
print("Done")
Next would be D401 First line should be in imperative mood and there are now few enough of these to do my hand later (again, waiting on the open pull requests as I already fixed some).
@peterjc Do you know that newer flake8 versions (since 3.7) have a per-file-ignores option? This allows to set up only one .flake8 file and still have folder specific ignores, e.g.:
This example doesn't make too much sense, I just used it for testing: I put too much empty lines in one file in Bio and one file in Tests, and indeed, only the file from the Tests folder was flagged.
@MarkusPiotrowski I did not know that - if as in your example it works nicely with folder level settings, that would do nicely (not that fixing the issues in Tests/ isn't a good idea anyway).
Once we've merged #2019 and #2020, do you want to try a single strict top-level .flake8 instead of #2018 - taking care of E731 etc as extra ignores for Bio/, and D202 etc as extra ignores on the Tests/ folder?
I found this just today. Didn't want that you spend your whole Easter Holidays with these issues...
Yes, I would like to give it a try. Do you need to update flake8?
One of the interesting things about my employer is we don't get public holidays (although the institute does close over Christmas into New Year), so if we take them off they come out of (reasonably generous) annual leave. I'll be back at work on Monday.
--
By all means, please have a play with the combined settings - I'm not planning on doing any more flake8 work today or the weekend (aside perhaps from merging pull requests).
I think we're now very close to having Bio/ and Tests/ having the same .flake8 settings, with BioSQL/ and Doc/examples/ even stricter. So will be soon be able to use a single top level .flake8 file.
The quick solution will be to adopt the Bio/.flake8 as the sole top level settings - but ideally using Markus' idea lets us have the stricter settings with additional ignores under Bio/ and Tests/ as needed 👍
I'm actually working on style issues in Scripts.
I already have made a 'top-level' .flake8 and I'm waiting now for some of the ongoing style-related PR's to be merged to test it.
Unfortunately, it seems that the per-file-ignores must be all on the same line per file pattern. I tried to put them one on each line with following comments, but that didn't work.
With this .flake8 file (not up-to-date regarding the running PRs):
[flake8]
doctests = True
ignore =
# =============================================================
# Biopython's 'standard' ignores we can agree to always accept:
# =============================================================
E501, # line too long TODO: Maybe we find a sensible limit, e.g. 88 (black) and enforce it
W503, # line-break before binary operator, deliberately ignore in favour of W504
D203, # 1 blank line required before class docstring
# We ignore D203 deliberately in favour of passing D211 No blank lines allowed before
# class docstring
# ===========================================
# Ignores that we have to accept for a while:
# ===========================================
E123, # closing bracket does not match indentation of opening bracket's line (top, Bio, Tests, 132 occurrences)
W504, # line break after binary operator TODO?
B007, # Loop control variable not used within the loop body.
# If this is intended, start the name with an underscore.
#==========================================
# Optional ignores for local installations:
# =========================================
BLK100, # Black would make changes, only on local installations (so far)
per-file-ignores =
Bio/*:E122,E126,E731,F401,F841,D101,D102,D103,D105,B009,B010,B011,C812,C815
Tests/*:E122,E126,E241,E401,E731,F401,F405,F841,D100,D101,D102,D103,D202,D400,D401,D412,B009,B010,B011,C812
# This format is not allowed:
# per-file-ignores =
# /Bio/*:E122, # continuation line missing indentation or outdented TODO (271 occurrences)
# E126, # continuation line over-indented for hanging indent TODO (53 occurrences)
# E731, # do not assign a lambda expression, use a def TODO (28 occurrences)
# F401, # module imported but unused TODO (108 occurrences)
# F841, # local variable is assigned to but never used TODO (55 occurrences)
# D101, # missing docstring in public class TODO (43 occurrences)
# D102, # missing docstring in public method TODO (81 occurrences)
# D103, # missing docstring in public function TODO (17 occurrences)
# D105, # missing docstring magic method TODO (116 occurrences)
# B009, # do not call getattr with a constant attribute value,
# # it is not any safer than normal property access
# B010, # do not call setattr with a constant attribute value,
# # it is not any safer than normal property access
# B011, # Do not call assert False since python -O removes these calls;
# # instead callers should raise AssertionError().
# C812, # missing trailing comma
# C815 # missing trailing comma in Python 3.5+
# /Tests/*:E122, # continuation line missing indentation or outdented TODO (48 occurrences)
# E126, # continuation line over-indented for hanging indent TODO (41 occurrences)
# E241, # multiple spaces after ',' TODO (54 occurrences)
# E401, # module level import not at top of file TODO? (and noqa?) (49 occurrences)
# E731, # do not assign a lambda expression, use a def, we want deliberately ignore this in tests
# F401, # module imported but unused TODO (76 occurrences)
# F405, # name may be undefined, or defined from star imports: module TODO or noqa?,only 21 in tests
# F841, # local variable is assigned to but never used TODO? (68 occurrences)
# D100, # missing docstring in public module, TODO (75 occurrences)
# D101, # missing docstring in public class (220 occurrences)
# D102, # missing docstring in public method (976 occurrences)
# D103, # missing docstring in public functions TODO (50 occurrences)
# D202, # no blank lines allowed after function docstring (88 occurrences)
# D400, # first line should end with a period (742 occurrences)
# D401, # first line should be in imperative mood TODO(31 occurrences)
# D412, # no blank lines allowed between a section header and its content TODO(1 occurrence)
# B009, # do not call getattr with a constant attribute value,
# # it is not any safer than normal property access
# B010, # do not call setattr with a constant attribute value,
# # it is not any safer than normal property access
# B011, # Do not call assert False since python -O removes these calls;
# # instead callers should raise AssertionError()
# C812 # missing trailing comma
we get the following result:
G:\git_32bit\biopython>flake8 --statistics --quiet
.\setup.py
.\Doc\examples\ACT_example.py
.\Doc\examples\fasta_iterator.py
.\Doc\examples\fasta_dictionary.py
.\Doc\examples\getgene.py
.\Scripts\query_pubmed.py
.\Scripts\scop_pdb.py
.\Scripts\debug\debug_blast_parser.py
.\Scripts\GenBank\check_output.py
.\Scripts\Restriction\ranacompiler.py
.\Scripts\Restriction\rebase_update.py
.\Scripts\xbbtools\nextorf.py
.\Scripts\xbbtools\xbb_blast.py
.\Scripts\xbbtools\xbb_blastbg.py
.\Scripts\xbbtools\xbb_help.py
.\Scripts\xbbtools\xbb_search.py
.\Scripts\xbbtools\xbb_translations.py
.\Scripts\xbbtools\xbb_utils.py
.\Scripts\xbbtools\xbb_widget.py
.\Tests\test_NaiveBayes.py
.\Tests\test_seq.py
.\Tests\test_PDB_ResidueDepth.py
.\Tests\test_ExPASy.py
.\Tests\test_KGML_graphics_online.py
.\Tests\test_SeqIO_online.py
.\Tests\test_PDBList.py
.\Tests\test_TogoWS.py
.\Tests\test_phyml_tool.py
.\Tests\test_Uniprot.py
.\Tests\test_psw.py
.\Tests\test_SCOP_online.py
.\Tests\requires_wise.py
.\Tests\test_Wise.py
.\Tests\test_ClustalOmega_tool.py
.\Tests\test_Entrez_parser.py
.\Tests\test_HMMCasino.py
1 D100 Missing docstring in public module
18 D101 Missing docstring in public class
95 D102 Missing docstring in public method
14 D103 Missing docstring in public function
2 D105 Missing docstring in magic method
15 D107 Missing docstring in __init__
1 E126 continuation line over-indented for hanging indent
49 E402 module level import not at top of file
This does (of course) not include the running PRs, e.g. all the issues in /Scripts and /Tests are probably already solved and there may be only some single files that need further attention.
I agree that moving to pre-commit would allow including the misc checks currently done on TravisCI via the Tox configuration too - so that would be a practical improvement.
I suspect we could even use our current multiple .flake8 file setup with pre-commit, but I would rather move to a single top level .flake8 instead.
- [ ] I have read the ``CONTRIBUTING.rst`` file, have run ``flake8`` locally, and
understand that AppVeyor and TravisCI will be used to confirm the Biopython unit
tests and style checks pass with these changes.
The wording aims to cover the fact that TravisCI/Tox includes some extra style checks not currently done via flake8 (e.g. the RST linting)
Activity
peterjc commentedon Apr 18, 2019
This is a very good idea in principle, but the complexities of our different
.flake8settings in different folders is an annoyance requiring the bespoke git pre-commit script.I would very much like to address that first, which bring the enormous advantage of letting us use an off-the shelf widely used hook, e.g. that provided by
flake8itself:Currently (leaving aside optional extensions we don't currently require):
https://github.com/biopython/biopython/blob/biopython-173/BioSQL/.flake8 - quite strict
https://github.com/biopython/biopython/blob/biopython-173/Doc/examples/.flake8 - quite strict
https://github.com/biopython/biopython/blob/biopython-173/Bio/.flake8 - fairly strict
https://github.com/biopython/biopython/blob/biopython-173/Tests/.flake8 - least strict
This looks doable (and is part of my motivation with adopting the black formatting tool, #2008, which would take care of some of these). [Update 22 April: Actually black does not help much, other than E241, which autopep8 can do, we've already fixed all the flake8 style issues black would have handled]
Basically we need to fix a few things in the tests and/or relax the other tests a little.
peterjc commentedon Apr 18, 2019
I'm looking at D300 right now...
peterjc commentedon Apr 18, 2019
Pull requests opened to fix D300, D200 and D204 in Tests - a bit more effort on this and we can have a single
.flake8configuration, and use the default flake8 git pre-commit hook - which will be simpler to document and maintain 👍peterjc commentedon Apr 19, 2019
I propose to solve E731 the pragmatic way - whitelist most of them with
#noqalines, see #2019.I can fix D100 mostly automatically with the following script (missing docstrings can trigger false edits, and it leaves question marks and exclamation marks to a human to edit), will do this once the current pull requests are merged:
Next would be
D401 First line should be in imperative moodand there are now few enough of these to do my hand later (again, waiting on the open pull requests as I already fixed some).MarkusPiotrowski commentedon Apr 19, 2019
@peterjc Do you know that newer
flake8versions (since 3.7) have aper-file-ignoresoption? This allows to set up only one.flake8file and still have folder specific ignores, e.g.:This example doesn't make too much sense, I just used it for testing: I put too much empty lines in one file in
Bioand one file inTests, and indeed, only the file from the Tests folder was flagged.peterjc commentedon Apr 19, 2019
@MarkusPiotrowski I did not know that - if as in your example it works nicely with folder level settings, that would do nicely (not that fixing the issues in
Tests/isn't a good idea anyway).Once we've merged #2019 and #2020, do you want to try a single strict top-level
.flake8instead of #2018 - taking care of E731 etc as extra ignores forBio/, and D202 etc as extra ignores on theTests/folder?MarkusPiotrowski commentedon Apr 19, 2019
I found this just today. Didn't want that you spend your whole Easter Holidays with these issues...
Yes, I would like to give it a try. Do you need to update flake8?
peterjc commentedon Apr 19, 2019
One of the interesting things about my employer is we don't get public holidays (although the institute does close over Christmas into New Year), so if we take them off they come out of (reasonably generous) annual leave. I'll be back at work on Monday.
--
By all means, please have a play with the combined settings - I'm not planning on doing any more flake8 work today or the weekend (aside perhaps from merging pull requests).
peterjc commentedon Apr 22, 2019
I think we're now very close to having
Bio/andTests/having the same.flake8settings, withBioSQL/andDoc/examples/even stricter. So will be soon be able to use a single top level.flake8file.The quick solution will be to adopt the
Bio/.flake8as the sole top level settings - but ideally using Markus' idea lets us have the stricter settings with additional ignores underBio/andTests/as needed 👍MarkusPiotrowski commentedon Apr 22, 2019
I'm actually working on style issues in
Scripts.I already have made a 'top-level'
.flake8and I'm waiting now for some of the ongoing style-related PR's to be merged to test it.peterjc commentedon Apr 22, 2019
This time round, let's put each ignore code on its own line (sensibly sorted) as it will make tracking changes much easier?
MarkusPiotrowski commentedon Apr 22, 2019
Unfortunately, it seems that the
per-file-ignoresmust be all on the same line per file pattern. I tried to put them one on each line with following comments, but that didn't work.MarkusPiotrowski commentedon Apr 22, 2019
With this
.flake8file (not up-to-date regarding the running PRs):we get the following result:
This does (of course) not include the running PRs, e.g. all the issues in
/Scriptsand/Testsare probably already solved and there may be only some single files that need further attention.peterjc commentedon Apr 23, 2019
Do you know if this style would work? If so could opt for even more path repetition to get one code per line?
(If you don't known, I might try this later today)
13 remaining items
peterjc commentedon May 16, 2019
Added 21 Nov 2018, I think I'd missed that.
I agree that moving to
pre-commitwould allow including the misc checks currently done on TravisCI via the Tox configuration too - so that would be a practical improvement.I suspect we could even use our current multiple
.flake8file setup withpre-commit, but I would rather move to a single top level.flake8instead.peterjc commentedon May 23, 2019
With #2074 merged, @MarkusPiotrowski are you happy for us to recommend the flake8 pre-commit hook in the
CONTRIBUTING.rstfile (etc)?Update contributing for single .flake8 file
Update contributing for single .flake8 file
peterjc commentedon May 24, 2019
Good progress, I've closed #493 as of #2075.
Still need to mention the hook on https://biopython.org/wiki/GitUsage
Also consider if and how to mention it in the
PULL_REQUEST_TEMPLATE.mdtoo.peterjc commentedon May 24, 2019
How about this:
The wording aims to cover the fact that TravisCI/Tox includes some extra style checks not currently done via flake8 (e.g. the RST linting)
MarkusPiotrowski commentedon May 24, 2019
Fine!
Encourage use of flake8 in pull request template
peterjc commentedon May 24, 2019
Change applied - are we OK to close this issue?
MarkusPiotrowski commentedon May 24, 2019
Yes, I'm doing so now. Thank you!
peterjc commentedon May 24, 2019
Excellent work, thank you too.
Encourage use of flake8 in pull request template
Update contributing for single .flake8 file
Encourage use of flake8 in pull request template