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

Add Doc Linting to CI #294

Merged
merged 18 commits into from
Mar 25, 2020
Merged

Add Doc Linting to CI #294

merged 18 commits into from
Mar 25, 2020

Conversation

mikemhenry
Copy link
Collaborator

@mikemhenry mikemhenry commented Feb 17, 2020

Add automated doc string checking to CI

Description

We are using pydocstyle to check that our document strings are in the numpy docstring style. The configuration for pydocstyle is in setup.cfg. For now I'm keeping things rather basic, but we might find it worth printing more detailed information once we get everything passing. I also chose signac/core/jsondict.py as the first file for testing this, feel free to suggest another file if you think there is a better candidate.

Before we fix the issues with this file's document strings, I want to make sure CI will throw an error.

@jennyfothergill is co-authoring this PR.

Motivation and Context

See this issue for more detail:
glotzerlab/signac-docs#64

Types of Changes

  • Documentation update
  • Bug fix
  • New feature
  • Breaking change1

1The change breaks (or has the potential to break) existing functionality.

Checklist:

If necessary:

  • I have updated the API documentation as part of the package doc-strings.
  • I have created a separate pull request to update the framework documentation on signac-docs and linked it here.
  • I have updated the changelog and added all related issue and pull request numbers for future reference (if applicable). See example below.

Example for a changelog entry:
Add docstring linting to CI
Fix docstring formatting in signac/core/jsondict.py

@mikemhenry
Copy link
Collaborator Author

Looks like CI is working how I would expect and fails due to some formatting errors.

@vyasr
Copy link
Contributor

vyasr commented Feb 19, 2020

@mikemhenry what sort of input will it take to get this out of draft? What decisions need to be made to move this PR forward? Deciding whether pydocstyle is the right tool?

@vyasr
Copy link
Contributor

vyasr commented Feb 26, 2020

@mikemhenry how are things here? If possible, it would be nice to make progress with this PR so that we can have some of our new contributors look into the downstream issues.

@mikemhenry
Copy link
Collaborator Author

Next steps to get this out of draft:

  1. Refactor our CI a bit to separate out code linting, doc linting, and dependency install.
  2. Confirm the CI fails for doc string testing
  3. Fix the file
    Then we can merge 🎉

@mikemhenry
Copy link
Collaborator Author

@bdice I've made some changes to the CI, looking at the output it looks good to me, was that what you were thinking?

@bdice
Copy link
Member

bdice commented Feb 29, 2020

@mikemhenry Looks swiggity sweet to me. With that, (1) and (2) are done. Then we just fix that file (3) and it will be ready to merge. After that we can open issues to improve doc style for each submodule (signac.contrib, signac.core, etc.) and explicitly exclude the deprecated bits like signac.db.

@mikemhenry
Copy link
Collaborator Author

Okay it should pass the linting now, but I put in some place holder """Doc string here.""" for the classes and methods that were missing them. I would be happy to take suggestions on what the doc strings should be @bdice @vyasr @csadorf

@codecov
Copy link

codecov bot commented Mar 3, 2020

Codecov Report

Merging #294 into master will decrease coverage by 11.02%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #294       +/-   ##
===========================================
- Coverage   76.18%   65.15%   -11.03%     
===========================================
  Files          43       40        -3     
  Lines        7076     5700     -1376     
===========================================
- Hits         5391     3714     -1677     
- Misses       1685     1986      +301
Impacted Files Coverage Δ
signac/core/jsondict.py 95.34% <100%> (ø) ⬆️
signac/db/database.py 0% <0%> (-100%) ⬇️
signac/__main__.py 0% <0%> (-80%) ⬇️
signac/common/crypt.py 0% <0%> (-76.75%) ⬇️
signac/common/host.py 0% <0%> (-46.43%) ⬇️
signac/common/validate.py 39.13% <0%> (-39.14%) ⬇️
signac/common/connection.py 0% <0%> (-38.28%) ⬇️
signac/common/config.py 70.37% <0%> (-15.75%) ⬇️
signac/contrib/filesystems.py 33.96% <0%> (-12.27%) ⬇️
signac/contrib/utility.py 51.49% <0%> (-7.19%) ⬇️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 232d018...554bc6c. Read the comment docs.

@csadorf
Copy link
Contributor

csadorf commented Mar 4, 2020

Okay it should pass the linting now, but I put in some place holder """Doc string here.""" for the classes and methods that were missing them. I would be happy to take suggestions on what the doc strings should be @bdice @vyasr @csadorf

Can you create a list linking to those placeholders and then we can work through them?

@mikemhenry
Copy link
Collaborator Author

mikemhenry commented Mar 4, 2020

@csadorf Done!

BufferException

JSONDict

BufferedSyncedAttrDict

@vyasr
Copy link
Contributor

vyasr commented Mar 9, 2020

As per PyCQA/pydocstyle#60, I'm in favor of not requiring docstrings for magic methods. pydocstyle supports suppressing this warning, and I think that makes sense since the behavior of most magic methods should be obvious in the majority of cases.

  • JSONDict.buffered: A context manager for buffering reads from and writes to this JSONDict that flushes all changes when the context is exited.
  • BufferedSyncedAttrDict: A buffered :class:~.SyncedAttrDict that saves all changes in memory but does not write them to file until :meth:~.flush is called.
  • BufferedSyncedAttrDict.flush: Save buffered changes to the underlying file.

For load and save, I'd prefer to add the documentation to the parent class (_SyncedDict). Does pycodestyle correctly detect inheritance of docstrings? Most Python tools (like Sphinx and help) support this, so I would hope pycodestyle would as well.

@csadorf @bdice thoughts?

@mikemhenry
Copy link
Collaborator Author

mikemhenry commented Mar 9, 2020

I'm fine with ignoring magic methods as a default. If during a code review there is a magic method that seems confusing, that would be the time to make sure we get it documented. RE docstring inheritance, I will check to see if pydocestyle supports it. Since right now I only whitelist one file, that might interfere with its abilities.

@mikemhenry
Copy link
Collaborator Author

I haven't found a tool that will be able to lint docstrings and understand inheriting them from different classes and it is a know issue: PyCQA/pydocstyle#309
I decided to go with the noqa method, but we can switch to using a decorator or something else.

@mikemhenry mikemhenry marked this pull request as ready for review March 18, 2020 19:41
@mikemhenry mikemhenry requested review from a team as code owners March 18, 2020 19:41
@mikemhenry mikemhenry requested review from csadorf and removed request for a team March 18, 2020 19:41
@mikemhenry mikemhenry requested review from jennyfothergill and removed request for a team March 18, 2020 19:41
@mikemhenry
Copy link
Collaborator Author

I had to manually re-run some tests but everything passes now and this PR is ready for review!

@mikemhenry mikemhenry requested a review from bdice March 18, 2020 19:44
Copy link
Member

@bdice bdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikemhenry I pushed one set of minor edits and have one comment. Otherwise approved.

signac/core/jsondict.py Outdated Show resolved Hide resolved
@bdice bdice added documentation Writing or editing documentation enhancement New feature or request labels Mar 19, 2020
@bdice bdice added this to the v1.5.0 milestone Mar 19, 2020
Copy link
Contributor

@csadorf csadorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc-string for the __str__ method still needs to be removed, and I've made two suggestions for improvement, but otherwise this looks good to me. Thx a lot!

signac/core/jsondict.py Outdated Show resolved Hide resolved
signac/core/jsondict.py Outdated Show resolved Hide resolved
signac/core/jsondict.py Outdated Show resolved Hide resolved
@bdice
Copy link
Member

bdice commented Mar 25, 2020

I am going to merge this since it has 2 approvals - I applied a couple of small changes at the end to ignore D105. To ignore D105, I had to disable the "numpy" convention. I reviewed the rules that are ignored by the numpy convention and I removed a couple of those ignore rules (so we're slightly "stricter"). See here for info: http://www.pydocstyle.org/en/latest/error_codes.html#default-conventions

@bdice bdice merged commit 906e144 into glotzerlab:master Mar 25, 2020
@mikemhenry
Copy link
Collaborator Author

Sweet, thanks so much for taking those lest steps!

@mikemhenry mikemhenry deleted the feat/doc_lint branch March 28, 2020 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Writing or editing documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants