-
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
Enable ruff's pydocstyle (D) rules and remove docformatter #2925
Conversation
``` $ ruff check pygmt doc/conf.py examples --statistics 645 D200 [*] One-line docstring should fit on one line 312 D205 [ ] 1 blank line required between summary line and description 123 D400 [ ] First line should end with a period 30 D401 [ ] First line of docstring should be in imperative mood: "A mock GMT API function that always returns a given value." 30 D412 [*] No blank lines allowed between a section header and its content ("Examples") 12 D202 [*] No blank lines allowed after function docstring (found 1) ```
@@ -445,7 +445,7 @@ def fmt_docstring(module_func): | |||
- J = projection | |||
- R = region | |||
<BLANKLINE> | |||
""" | |||
""" # noqa: D410,D411 |
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.
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.
Actually, this line is required. If removing noqa: D410, D411
, the codes will be formatted with the following diff:
diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py
index 57bd0f900..b44dd7fec 100644
--- a/pygmt/helpers/decorators.py
+++ b/pygmt/helpers/decorators.py
@@ -425,6 +425,7 @@ def fmt_docstring(module_func):
<BLANKLINE>
My nice module.
<BLANKLINE>
+
Parameters
----------
data : str, numpy.ndarray, pandas.DataFrame, xarray.Dataset, or geo...
@@ -445,7 +446,7 @@ def fmt_docstring(module_func):
- J = projection
- R = region
<BLANKLINE>
- """ # noqa: D410,D411
+ """
filler_text = {}
if hasattr(module_func, "aliases"):
Then the doctest fails, because only one blank line is expected, but two blank lines are given (one is <BLANKLINE>
, another one is the newly added blank line).
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.
We could just remove the Oh wait, doesn't seem to work, hold on.<BLANKLINE>
from L427 no?
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.
Yeah, looks like we'll need to keep it, since doctest takes an empty line to mean the end of the expected output according to https://docs.python.org/3/library/doctest.html#how-are-docstring-examples-recognized
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.
Thanks again @seisman for all the work simplifying the code formatters to just ruff
! Now make format
runs in less than a second 🚀
Better to review the commits one by one to understand the changes.
In b9c4d42, we enable ruff's pydocstyle (D) rules and set the docstring convention to "numpy".
After setting the "numpy" convention, we have to fix/ignore some violations (done in fa93c37, 092075a, 608f38d, 0f9cb0b, d9116bd, f22bfa0, 1280a1c).
After the above fixes, we still have hundreds of violations against 6 rules, as shown below:
D200
: This is against our current style, so it must be disabled.In commit 3170401, these 6 rules are disabled.
As the documentation says (https://docs.astral.sh/ruff/faq/#does-ruff-support-numpy-or-google-style-docstrings):
Among these rules,
D213
andD410
make sense to the project and are enabled in commit 5d983e6.Then docformatter can be fully replaced by ruff and is removed in commit 435290f. The contributing guides are updated in 6e04543.
Please also note that, in the old settings, docformatter wraps docstrings at 79 characters. If we change the docformatting settings to 88, then the summary lines can be automatically rewrapped to 88 characters, as mentioned in #962 (comment). However, ruff's pydocstyle rules can't wrap long lines and only raise warnings. So, ruff is not as powerful as docformatter. In other words, we may want to change docformatter line-length settings to 88 (as done in #962 (comment)) and let docformatter rewrap lines to 88 characters before completely removing it (Done in #2926).
Closes #962.