-
Notifications
You must be signed in to change notification settings - Fork 230
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
[MRG][DOC] Fixes almost all warnings in the docs #338
Conversation
Thanks a lot @mvargas33, this is a really useful contribution. |
Also, the references and example environments are a bit ugly visually (just a simple border with possibly overlarge margins). Maybe there is a way to make this a bit more nice? |
I've changed the CSS of Example Code and References for a custom one. You can notice the differences here before and after this PR. |
Forgot to mention that this approach don't use Also, with this last commit, I've added all methods from all classes to their respective So in the end, each class has a summary of all of its methods (in addition to the attributes and references and so on) and then the detailed description of each method. I also added the This PR is ready for a code review. Summary:
|
metric_learn/sdml.py
Outdated
@@ -285,6 +331,39 @@ class SDML_Supervised(_BaseSDML, TransformerMixin): | |||
The linear transformation ``L`` deduced from the learned Mahalanobis | |||
metric (See function `components_from_metric`.) | |||
|
|||
Methods |
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 may have missed it in your PR description, but why do we need a full method listing in each class docstring? I expect the doc building process to handle method listings automatically.
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 expected that as well but it does not happen. So it all started because there is a lot of warnings like these:
/home/max/inria/metric-learn/metric_learn/sdml.py:docstring of metric_learn.sdml.SDML_Supervised:82: WARNING: autosummary: stub file not found 'metric_learn.SDML_Supervised.get_params'. Check your autosummary_generate setting.
See these image as reference.
And I've found the solution in stackoverflow from a person that was also extending from the Estimator
class and had exactly the same errors. So I followed his advice and added the Method
directive in every class, and that removed all these bunch of warnings.
Without explicitly adding this directive, no method summary is shown in the docs, just the detailed method list.
I also thought that the Method
directive could be incremental, so for each class I only had to add the methods description of that class, and not the method description of his parent, and grandparent class as well. But sadly it doesn't work that way either.
It may look like an overkill right now, but thinking about it, when someone has to add another algorithm in the future, you already have the docstrings from other algorithms as reference, so it won't be overwhelming.
Also, if someone wants to extend the docs, it's better for them to see the warnings/errors that only they are producing, because right now its really really hard to debug the docs with all these warnings. @wdevazelhes says it at #305 as well (in this case for the 'any' flag, the second bunch of warnings).
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.
Regarding this: how about the second answer in the stackoverflow post you linked: https://stackoverflow.com/questions/65198998/sphinx-warning-autosummary-stub-file-not-found-for-the-methods-of-the-class-c
This could provide a way to remove the warnings. We would not have any method summary, but we have the list afterwards, so it is not a big deal considering the effort required to have the method summary. Of course the best solution would be that the summary is constructed automatically, but you seem to say that it is not possible.
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 been hours looking to build the methods summary automatically without any warning, without success.
We either use numpydoc_show_class_members = False
removing the warnings but loosing the automatic method summary, or
We keep the implicit numpydoc_show_class_members = True
generating the automatic method summary but with a bunch of warnings.
Yes, I realized that the method summary its actually being generated with the docs as they are. So I will remove the hard coded method summary that I've made, as it's a lot of work and can be done automatically, despite the warnings.
Here is a quick preview of the |
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.
Here are some additional comments
.. rubric:: References | ||
|
||
|
||
.. container:: hatnote hatnote-gray |
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.
it would be nice it there was a way to define a custom rubric or something so we only need to write something like
.. rubric:: References
and the appropriate CSS style would be automatically applied
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.
(no big deal if there is no easy way to do this)
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.
After researching for while, there is not a clear path to this at all. Also, I think that even if its possible all .. rubric::
stuff will have the same CSS, including the Examples, so I guess its not a good idea to have this CSS globally, because we don't want grey boxes everywhere, just in the references.
So I've removed the I've hardly tried to keep the methods summary generation without warnings, but I failed to do so. I think its ok for now to keep this kind of warnings, because hard-coding the |
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.
LGTM, thanks a lot!
Closes #226
Closes #305
While doing the docs for #333 #329 and #330 I've encountered an enormous amount of warnings while executing
make html
. This PR solves most of these warnings while leaving a small number of warnings open to discussion. Here's a detail of the changes:setup.py
solved a typo inshinx_rtd_theme
forsphinx_rtd_theme
. Also addedsphinx-gallery
andmatplotlib
, both needed to render the docs for the examples.conf.py
, at line 82 and 83add_stylesheet
need to be changed foradd_css_file
, andadd_javascript
foradd_js_file
. Alsohtml4_writer = True
at line 72 is deprecated by an explicit warning fromsphinx_rtd_theme
, so it's commented now.any
flag: As stated in [DOC] Removeany
flag #305 theany
flag is causing more trouble than benefit. So I commented it. Tested some refs in the docs and they seem to work as usual.Topic
directive without body: Eachtopic
directive regarding ''Example Code'' had no body, mainly insupervised.rst
andweakly_supervised.rst
. Introduced a brief description of the code whenever necessary, like "Example Code: A basic usage of this model with the Iris dataset from scikit-learn."supervised.rst
,weakly_supervised.rst
andunsupervised.rst
there is still an issue:.. topic:: References:
it means that something was referred previously. But in this case, this section is used as "find the original paper here" or "base code was taken from here" at the end of each algorithm description. None of the references is mention earlier in any text body, and because of that this kind of warning shows up:/metric-learn/doc/unsupervised.rst:39: WARNING: Footnote [1] is not referenced.
rst
file the numeration of references must strictly increase, but in this case, each algorithm has references from 1-2 or 1-3, and because of that there are a lot of warnings of the form/metric-learn/doc/supervised.rst:378: WARNING: Duplicate explicit target name: "1".
Which makes sense, because if I want to reference the target [1] in a text body, there are 6 or 7 references with that name.Some possible solutions:
.. topic:: References:
but just a list instead, this will delete all warnings.Besides this last problem, all warnings were fixed.