-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Standardization of reST section markups via CI #3975
Comments
Initially I was thinking of writing a CLI script to detect + autofix (which was the original method I used to fix #3973), but I eventually settled on writing a custom It is designed to be extendible as well, so we can easily add more custom style checks in the future (not necessarily just for docstrings). Just as a preview, these are the error codes I'm considering to implement:
|
I did not know you can make custom flake8 plugins. That sounds like a nice addon and fits our CI.
I believe this agrees with: https://numpydoc.readthedocs.io/en/latest/example.html 👍 |
There is a flake8 plugin that checks for numpy doc style: https://pypi.org/project/flake8-docstrings, which allows you to do: flake8 --docstring-convention numpy Example output on
Which seems useful overall. But it does not capture the empty lines below an Examples block... Also, it does depend on |
@zundertj Thanks, yeah I saw that plugin as well during my initial research. Unfortunately that
But later I thought it is better to wrap these regex'es within a Flake8 plugin so that we don't have to make a separate script call in our Makefile (in Ultimately the goal here is to achieve a consistent docstring style within the project (some of these style violations will lead to wrong rendered output, cf. some of my previous PRs; some violations are just a matter of style). But I do empathize with the concern that this will be adding yet another thing we have to maintain in the long-term. If there exists a plugin/tool that can check for the aforementioned violations, I fully agree on the sentiment to rely on existing (well-maintained) tools. |
Just flagging that there are some similar tools. Good to know you did you come across that as well, and it indeed doesn't solve our use case, although one would hope it does. So it is not surprising that every (big) Python project ends up rolling their own docstring validation script. To mitigate the maintenance argument, I think it would best to make it an external package:
Downside is that a separate repo and package needs to be set up, but it seems you are up for that task? And as you said, can just be a couple of regex to start with, not expecting a full blown linter. Hooking into flake8 as a plugin seems sensible to me. |
Sure, I think that makes sense. Will update here when I get around to doing that. |
Okay, maybe the whole flake8 plugin business isn't necessary after all. 😅 Just realized there is validation built right into numpydoc, that should get us at least 50% of the way there. We can either trigger the docstring validation during sphinx build, looks a little like this: The sphinx build fails eagerly (which might be useful in CI ?). Or use something like numpydoc-validation to run the validation as an external check on the whole Given that this is directly from the numpydoc team, I suppose we can just go with whatever they are using rather than our own interpretation of their style (though, it doesn't seem like all of their error codes are compliant with their example..) |
I just found this issue after opening my PR #4155. I looked into pydocstyle, which is behind flake8-docstrings. Regarding the lints you are looking for:
So I really don't see the need for a custom tool here! |
As follow-up from #3973 , and related discussion from #3932 .
Following the numpydoc styleguide, we will be adopting the style of no newline after the section header, like so:
instead of
The suggestion here is to add a check in our documentation-CI to enforce this style as a hard check moving forward.
The text was updated successfully, but these errors were encountered: