-
Notifications
You must be signed in to change notification settings - Fork 4k
Add pre-commit hook to validate docstrings with pydocstyle #5776
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
Conversation
|
I'm not sure why autoflake is failing in |
|
Changed to a draft PR as some aspects of this change could use Product review first. |
| run: | | ||
| # Run eslint as a standalone command to generate the test report. | ||
| PRE_COMMIT_NO_CONCURRENCY=true SKIP=eslint pipenv run pre-commit run --show-diff-on-failure --color=always --all-files | ||
| PRE_COMMIT_NO_CONCURRENCY=true SKIP=eslint,pydocstyle pipenv run pre-commit run --show-diff-on-failure --color=always --all-files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want to disable this check in CI? Can you update the comment below?
| - --convention=numpy | ||
| - --add-ignore=D100,D101,D104,D105,D106,D107 | ||
| - --add-select=D417 | ||
| - --match-dir=(lib\/streamlit\/)(?!vendor)(?!watcher) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use the files/exclude option for pre-commit-hook, this check will only run when we make changes to matching files.

Now, this check will be run when we modify any python file.
types: [python]
https://github.com/PyCQA/pydocstyle/blob/master/.pre-commit-hooks.yaml#L6
Here is fix: #5790 |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
📚 Context
The docstrings in Streamlit's codebase (specifically, the public API) loosely conform to the
numpy(akanumpydoc) convention. The specific rules of thenumpyconvention we follow and don't follow haven't been explicitly laid out.What kind of change does this PR introduce?
🧠 Description of Changes
This PR does two things:
numpyconvention we follow and those we ignore. Read Error Codes for an exhaustive list of all possible rules.pydocstyleoperates on.pyfiles and not function names. As such, the pre-commit hook in point 2 validates docstrings in.pyfiles inlib/streamlit/(which contains all .py files corresponding to all public Streamlit commands), excludinglib/streamlit/vendorandlib/streamlit/watcher(both sub dirs don't contain .py files with public API commands).pydocstyleto validate if docstrings pass all the rules except the ones mentioned below:Rules we follow
The subset of rules from
pydocstyle's Error Codes we follow are:Rules we ignore
What's not covered in this PR
pydocstylepre-commit hook operates only on staged files in git.What's next?
The PR ensures that the
pydocstylecheck will run against any new or modified.pyfiles in(lib\/streamlit\/)(?!vendor)(?!watcher). It leaves unanswered the question: "How do we ensure existing docstrings are validated ?".That question can be answered using one or both of these options:
This PR, however, is independent of the above question and can be merged before it is answered.