-
Notifications
You must be signed in to change notification settings - Fork 224
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 docformatter to format plain text in docstrings #642
Conversation
bfbe503
to
3589c88
Compare
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.
Mixed feelings about using docformatter
here. There are some aspects of PEP 257 that are nice, while others seem strange (though it might just require some getting used to). As you mentioned too at #642 (comment), the version of docformatter (1.3.1) from PyPI is somewhat out of date (11 Nov 2019) and there's features in the master branch which would be nice to have!
Also a bit wary about adding yet another lint tool into our toolbox since it might put off new contributors. The intention is good (making it easier to style code), but we'll need to remind ourselves to put code before formatting (as mentioned in https://github.com/GenericMappingTools/pygmt/blob/master/MAINTENANCE.md#reviewing-and-merging-pull-requests).
Callback function that the GMT C API will use to print log and | ||
error messages. We'll capture the messages and print them to stderr | ||
so that they will show up on the Jupyter notebook. | ||
error messages. | ||
|
||
We'll capture the messages and print them to stderr so that they | ||
will show up on the Jupyter notebook. |
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.
So docformatter splits things up here, the first sentence is a 'summary', and the other sentences become a 'description'. Interesting.
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.
I think "summary" can be only one sentence, so the "summary" and "description" is separated at the first "period".
pygmt/sphinx_gallery.py
Outdated
""" | ||
Called by sphinx-gallery to save the figures generated after running | ||
code. | ||
""" | ||
"""Called by sphinx-gallery to save the figures generated after running | ||
code.""" |
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.
This looks funny too, why doesn't docformatter
put a newline here? Seems to be raised before at PyCQA/docformatter#9.
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.
Once PyCQA/docformatter#49 is merged (and a docformatter
release is made), then we can rerender things and hopefully get a smaller diff.
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.
Docformatter 1.4 has been released at https://pypi.org/project/docformatter/1.4/ so we can try to finish up this PR.
Perhaps we can ask if they could have a new release.
It seems straightforward to support slash commands like |
It's been asked at PyCQA/docformatter#55.
Ah that does look neat! |
Let's keep this PR open for a while. |
096ac84
to
2557e8f
Compare
a7b6f3d
to
d9822c2
Compare
d9822c2
to
0fcfb24
Compare
0fcfb24
to
54213f7
Compare
Makefile
Outdated
@@ -6,6 +6,8 @@ PYTEST_COV_ARGS=--cov=$(PROJECT) --cov-config=../pyproject.toml \ | |||
--pyargs ${PYTEST_EXTRA} | |||
BLACK_FILES=$(PROJECT) setup.py doc/conf.py examples | |||
BLACKDOC_OPTIONS=--line-length 79 | |||
DOCFORMATTER_FILES=$(PROJECT) setup.py doc/conf.py examples | |||
DOCFORMATTER_OPTIONS=--recursive --pre-summary-newline --wrap-summaries 79 --wrap-descriptions 79 |
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.
DOCFORMATTER_OPTIONS=--recursive --pre-summary-newline --wrap-summaries 79 --wrap-descriptions 79 | |
DOCFORMATTER_OPTIONS=--recursive --pre-summary-newline --make-summary-multi-line --wrap-summaries 79 --wrap-descriptions 79 |
Do we want to force --make-summary-multi-line
(see https://github.com/myint/docformatter/tree/v1.4#options)? This will turn every description (even short ones) into:
"""
This is a description.
"""
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.
Yes, it looks cleaner.
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.
Just find that PEP 257 says:
Unless the entire docstring fits on a line, place the closing quotes on a line by themselves.
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.
Hmm, seems like docformatter
didn't implement that one-line docstring PEP 257 guideline correctly? I think it's ok to just force multi-line though, as long as there's an automated solution.
Co-authored-by: Wei Ji <[email protected]>
/format |
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.
Just one nitpick on alphabetically ordering, otherwise should be good to merge once the Style Checks tests pass.
Edit: /format
command at #642 (comment) didn't work because we need to install docformatter
at this line too:
pip install black blackdoc flake8 isort |
Co-authored-by: Wei Ji <[email protected]>
/format |
Might need to do it manually locally for now, the Github Action is using the workflow yaml file from the master branch. |
…ols#642) * Add docformatter to format docstrings following a subset of PEP 257 * Add --make-summary-multi-line * Install docformatter to make /format work * Sort dependencies alphabetically in environment.yml and requirements-dev.txt * Format all docstrings Co-authored-by: Wei Ji <[email protected]>
Description of proposed changes
Add
docformatter
to format plaintext in docstrings, as mentioned in #497.docformatter follows PEP 257, which is compatible with numpydoc style.
EDIT: There may be some incompatibility. The new documentation will look messy if
--pre-summary-newline
is not used.Preview the documentation: https://pygmt-git-docstring-formatter.gmt.vercel.app/
Fixes #497.
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.