-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Standardize Python Documentation styles #3003
Comments
Good catch! We should follow the documentation style from PyTorch, which uses |
cc @brianjo |
I'll see if I can find any guidance we have for this and I'll write some up, if I can't find anything. Thanks! |
I've been investigating this a bit and here's what I'm thinking. We want to:
napoleon_numpy_docstring = False
napoleon_google_docstring = True in
We can turn sphinx warnings into error as suggested in #3259 (comment) so that the CI can enforce such checks. Note that turning sphinx warnings into errors means that the CI will start failing with other kinds of doc-related issues: this isn't a big deal IMHO because there are few of these: only 37 sphinx warnings are raised as-of now, so they don't appear too often.
[pydocstyle]
ignore=D100,D101,D102,D103,D104,D105,D106,D107,D200,D201,D202,D203,D204,D205,D206,D207,D208,D209,D210,D211,D212,D213,D214,D215,D300,D301,D302,D400,D401,D401,D402,D403,D404,D405,D406,D407,D408,D409,D410,D411,D412,D413,D414,D415,D416 This deactivate all checks but this one:
May I suggest to proceed with the following:
Thoughts @datumbox @fmassa ? I'm happy to follow up with PRs if you're happy with this solution |
@NicolasHug Great analysis and proposals, thanks for looking into it. @mattip Any thoughts on the above? |
+1 for changing the conf.py and fixing the sphinx errors, then tun on the nitpicky mode. What is the overlap between the warnings from sphinx and the warnings from pydocstyle? If sphinx makes the pydocstyle tool redundant, then maybe it is not needed? |
There are some redundancy (like checking for unexpected indentation), but as far as I can tell sphinx doesn't issue a warning when a parameter is missing from a function's docstring (item 2 above), which is what |
|
This all sounds great to me |
📚 Documentation
CurrentlyTorchVision uses different styles for documenting functions. Here are a few:vision/torchvision/io/image.py
Lines 116 to 130 in 973db14
vision/torchvision/io/image.py
Lines 135 to 144 in 973db14
vision/torchvision/models/mobilenet.py
Lines 15 to 25 in 973db14
vision/torchvision/transforms/transforms.py
Lines 195 to 210 in 973db14
It's worth selecting one style, standardizing all pydocs and putting a CI test to ensure new PR follows the standard.
Edit: A series of PRs have manually resolved many of the inconsistencies described here. What's missing is adding a CI test to verify that new PRs follow the same standard.
PyTorch seems to have done work towards this direction, so it's worth investigating if we should adopt their solution. See comment: #3259 (comment)
Another alternative is to adopt an open-source docstring linter such as darglint. It seems that it is capable of validating google-style docstrings, it's configurable via
setup.cfg
and available via pip.pip install darglint
Unfortunately it's quite slow at the moment:
Not parallelised run:
darglint torchvision
Parallelised run:
SECONDS=0 ; find torchvision -name "*.py" | xargs -n 1 -P 8 darglint ; echo $SECONDS
cc @seemethere @vfdev-5 @fmassa
The text was updated successfully, but these errors were encountered: