Skip to content

Improve pydocstyle (PEP257) compliance #1170

Closed

Description

@peterjc

Biopython aspires to follow Python's docstring style guidelines in PEP257 https://www.python.org/dev/peps/pep-0257/ (and use reStructuredText for the docstrings).

We run the automatic tool pydocstyle on the code as part of the automated TravisCI tests (also used on pull requests). Right now this is configured to ignore many style violations. For example, the new release of pydocstyle v2.0.0 added some extra checks, most of which I just disabled in order that our TravisCI builds pass - see cc2ad72

This issue is about (gradually) cleaning up PEP257 compliance issues as flagged by the latest version of the pydocstyle tool, and removing entries from the ignore setting in our .pydocstyle configuration file.

Note that in some cases we as a community might agree to continue to ignore some of these items.

To install/upgrade this tool, use something like this (or just pip if you are still on Python 2):

$ pip3 install --upgrade pydocstyle

The following command simples a useful way to see a tally table for picking off the rarest cases to fix them first. The cut is to remove the variable part of the some messages containing text from the offending line.

$ pydocstyle Bio/ BioSQL/ Tests/ Scripts/ Doc/ --ignore "" | grep "^        D" | cut -d "(" -f 1 | sort | uniq -c | sort -n
  11         D207: Docstring is under-indented
  12         D104: Missing docstring in public package
  18         D301: Use r""" if any backslashes in a docstring
  24         D214: Section is over-indented 
  33         D405: Section name should be properly capitalized 
  35         D211: No blank lines allowed before class docstring 
  40         D100: Missing docstring in public module
  43         D404: First word of the docstring should not be `This`
  63         D412: No blank lines allowed between a section header and its content 
  85         D103: Missing docstring in public function
 102         D212: Multi-line docstring summary should start at the first line
 104         D403: First word of the first line should be properly capitalized 
 108         D209: Multi-line docstring closing quotes should be on a separate line
 109         D210: No whitespaces allowed surrounding docstring text
 114         D413: Missing blank line after last section 
 118         D101: Missing docstring in public class
 123         D401: First line should be in imperative mood; try rephrasing 
 135         D208: Docstring is over-indented
 140         D406: Section name should end with a newline 
 142         D407: Missing dashed underline after section 
 187         D205: 1 blank line required between summary line and description 
 254         D200: One-line docstring should fit on one line with quotes 
 275         D105: Missing docstring in magic method
 283         D402: First line should not be the function's "signature"
 354         D204: 1 blank line required after class docstring 
 569         D400: First line should end with a period 
 590         D203: 1 blank line required before class docstring 
 623         D401: First line should be in imperative mood 
 746         D102: Missing docstring in public method
2344         D213: Multi-line docstring summary should start at the second line

Once you've picked an entry to work on, run pydocstyle again selecting just that entry, e.g.:

$ pydocstyle Bio/ BioSQL/ Tests/ Scripts/ Doc/ --select D104
...

I've marked this issue as "Easy Fix" in the hope of encouraging new-comers to try fixing some of these issues. If you would like to work on one of these (e.g. fixing the D104 entries), please comment below to avoid duplicated effort, before starting work and submitting a pull request.

Note we will ask you to agree to dual licence your contributions under both the Biopython License Agreement AND the BSD 3-Clause License (see #898) and if you are you happy to be thanked by name in the NEWS.rst and CONTRIB.rst files (and under what name if this is not clear from your GitHub profile).

Update: You may find some of the modules have loads of issues, and instead it may make sense to work on all the docstring style or reStructuredText problems in that module at once. That's fine too - but again please comment on this issue to avoid duplication of effort.

Thanks!

Update: See #1203 for all the D1## entries about missing docstrings.

Activity

  1. added
    good first issue
    on Apr 18, 2017
  2. morrme commented on Apr 19, 2017

    @morrme
    Contributor

    I would like to help with this, but as I'm new to your codebase, I'd need a little mentoring to get started.

  3. peterjc commented on Apr 19, 2017

    @peterjc
    MemberAuthor

    @morrme how about you try D211 then - it just means removing the blank lines which pydocstyle is complaining about?

    You'll need to fork the Biopython repository, make a new branch, install and run pydocstyle, fix the blank lines, commit the changes, push to your fork on GitHub, and then make a pull request. Does all of that make sense?

  4. morrme commented on Apr 19, 2017

    @morrme
    Contributor

    @peterjc yes, it does! i will get started with it and let you know if i run into any issues.

  5. morrme commented on Apr 19, 2017

    @morrme
    Contributor

    @peterjc all done! what is the next rule on your wishlist?

  6. peterjc commented on Apr 19, 2017

    @peterjc
    MemberAuthor

    @morrme Speedy! Thanks! Since you're not familiar with the codebase, I suggest you avoid the issues about missing docstrings. There are more blank line checks you could tackle if you like?

    Or how about D301? It theory it should be easy if you're familiar with r"string" notation for raw strings to avoid the need to slash escape special characters, but I've not looked at why these are present here.

    See also PyCQA/pydocstyle#249 - some of these fixes can surely be automated which will save lots of people effort in the long run.

  7. morrme commented on Apr 19, 2017

    @morrme
    Contributor

    @peterjc sure, which ones are the blank line checks? D201-D205?

    I can take a look at what is failing D301 as well.

    A lot of these can definitely be fixed automatically. I hope that issue you made gets some traction!

  8. added a commit that references this issue on Apr 20, 2017
  9. souravsingh commented on Apr 21, 2017

    @souravsingh
    Contributor

    @peterjc I think the coala PyDocStyleBear could be useful for automated checks.

  10. peterjc commented on Apr 21, 2017

    @peterjc
    MemberAuthor

    @souravsingh That looks like a Coala wrapper for pydocstyle, so wouldn't add anything directly, but using coala generally in our TravisCI/Tox style checks and/or git commit hook might be good. I suggest you comment on #883

  11. peterjc commented on Apr 25, 2017

    @peterjc
    MemberAuthor

    Cross reference PyCQA/pydocstyle#250 which would make it easier to merge changes to .pydocstyle and comment why we still ignore some entries.

  12. 62 remaining items

  13. peterjc commented on Nov 23, 2017

    @peterjc
    MemberAuthor

    Little change in the latest numbers, still ignoring the controversial D406 and D407:

    $ pydocstyle Bio/ --ignore D1,D203,D213,D406,D407 | grep "^        D" | cut -d "(" -f 1 | sort | uniq -c | sort -n
      12         D301: Use r""" if any backslashes in a docstring
      46         D205: 1 blank line required between summary line and description 
      62         D401: First line should be in imperative mood; try rephrasing 
     122         D400: First line should end with a period 
     395         D401: First line should be in imperative mood 
    $ pydocstyle --version
    2.1.1
    
  14. peterjc commented on Nov 23, 2017

    @peterjc
    MemberAuthor

    I'm working on D205 right now...

  15. peterjc commented on Nov 23, 2017

    @peterjc
    MemberAuthor

    I've started work on D400 now.

  16. peterjc commented on Nov 24, 2017

    @peterjc
    MemberAuthor

    Pull request #1462 would fix and enforce D205 and D400 via our TravisCI/Tox style check, which would leave missing docstrings (#1203) and the following:

    $ pydocstyle Bio/ --ignore D1,D203,D213,D406,D407 | grep "^        D" | cut -d "(" -f 1 | sort | uniq -c | sort -n
      12         D301: Use r""" if any backslashes in a docstring
      62         D401: First line should be in imperative mood; try rephrasing 
     375         D401: First line should be in imperative mood
    

    To be honest, while I would like to follow D401 imperative mood, it seems a very low priority.

    I have started work on D301, cross reference discussion on #1173.

  17. souravsingh commented on Nov 24, 2017

    @souravsingh
    Contributor

    I can work on the D401 if it is needed. If not, we can ignore the error.

  18. peterjc commented on Nov 24, 2017

    @peterjc
    MemberAuthor

    Once #1462 (corrected) is merged I think we can close this issue :)

    @saketkc If you want to try doing a few D401 cases, sure - give it a try. Please start on those modules you have contributed to and are most familiar with. Thank you.

  19. peterjc commented on Dec 11, 2017

    @peterjc
    MemberAuthor

    Current numbers,

    $ pydocstyle Bio/ --ignore D1,D203,D213,D406,D407 | grep "^        D" | cut -d "(" -f 1 | sort | uniq -c | sort -n
      62         D401: First line should be in imperative mood; try rephrasing 
     354         D401: First line should be in imperative mood 
    

    i.e. 416 cases of D401 which I have logged as #1473 as a low priority issue.

    Closing this as most of the pydocstyle checks now pass. Horray - thank you everyone who contributed to this effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationStyleTestinggood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions