-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
Align behavior of pre-commit hook and Sphinx extension #476
Conversation
…on like sphinx side.
… sides support it.
I think I have an issue with the type hints I added – I will comment when this is ready for review since I can't mark it as a draft. Edit: Actually seems to be related to upstream changes made while I was working on this. |
Issue has been solved. Ready for review. |
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.
@stefmolin Thanks for this refactor, it looks great!
I should have written out #466 more clearly, because I actually liked the way you had it implemented; it felt much more similar to how other tools like ruff
select their rules.
Since you have now looked at this code quite a bit, I'd like to hear your opinion on how it should look, in an ideal world.
I still think we can align the two, but am hoping we can deprecate the "Sphinx way" for the "pre-commit way".
@rossbar I think you've tried to explain to me before why numpydoc is a bit weird in the way it specifies rules, so perhaps you also want to weigh in.
|
||
``pyproject.toml``:: | ||
|
||
[tool.numpydoc_validation] | ||
ignore = [ | ||
checks = [ |
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've always found the numpydoc convention confusing; I think the exclusion list you had before is more logical.
@stefanv - I probably should have double-checked with you as well. Personally, I have not used the Sphinx extension for validation, so I can't speak to that. For my original use case, I wrote the pre-commit hook we merged last week and set it up on my personal and work projects to ignore certain rules. I imagine that the rule set is unlikely to change much if at all in the future and that most use cases for the Sphinx side are not just specifying a list of rules to run, but rather to run all and ignore a select few; therefore, I would agree with you that an ignore list as I had initially with the pre-commit hook is much easier to work with and more logical. The only reason I mirrored the Sphinx extension approach was to avoid breaking other projects' documentation builds. If we are comfortable with that though, then I am more than happy to switch both to the ignore list approach. |
What do you think, @rossbar? |
I have no preference re: how the configuration is implemented (i.e. an "allowlist", an "ignorelist", both, etc.) FWIW the sphinx configuration supports both; i.e. either specifying a subset as an
The thing that I don't like about the way the validation is currently structured is the validator runs all the checks no matter what, and the configuration only affects which are reported. IMO it'd be a major improvement to refactor the validation so that it is modular, and only the selected checks are actually run. This is way out of scope for this discussion though!
I'd tend to agree - in fact, I think many of the implemented rules are already overly-specific to the point of not being very helpful.
IME in trying this out for large, existing doc sets (e.g. numpy, scipy, networkx, etc.) - this hasn't been the case. Most of the validation checks fire way too often and add a bunch of noise, to the point where there are only a few that are worth enabling. Automatic reformatting (a la linters) would help alleviate this a lot, but again that's for another feature discussion. |
With the changes currently in this PR, the pre-commit hook also supports both using the same logic.
In that case, perhaps it makes sense to use the Sphinx configuration for the pre-commit hook since you can provide a few rules to use rather than having to specify many to ignore. |
+1 from me! You'll need to override branch protection rules to merge since pre-commit.ci won't run on this PR |
Let's get this in, and work towards refactoring the checking to not do unnecessary work in the future. Thanks so much @stefmolin! |
@jarrodmillman looks like this broke MNE-Python: Probably should sort this out before releasing! |
ignore_validation_comments = extract_ignore_validation_comments( | ||
doc.source_file_name | ||
).get(doc.source_file_def_line or 1, []) |
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 this needs a if doc.source_file_name is not None
perhaps?
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 for the heads-up!
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.
How did the Sphinx validation behave before when the source_file_name
is None
? Do you still run the validation?
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. We're generate some doc strings on the fly, I assume that's what's breaking this but not sure
Closes #466
Changes made:
numpydoc_validation_checks
on the Sphinx side.numpydoc_validation_exclude
.override_GL08
pre-commit option, which is covered by the global exclusion option.--validate
sides.numpydoc_validation_overrides
, which allows the same flexibility that theoverride_<code>
options in the pre-commit hook provide. Included this option in thedoc/install.rst
page and added some test cases.doc/validation.rst
.