Skip to content

Docstrings for methods are missing in generated docs - #217

Merged
astrofrog merged 7 commits into
astropy:masterfrom
astrofrog:docs/fix-autosummary-methods
Jun 2, 2012
Merged

astrofrog merged 7 commits into
astropy:masterfrom
astrofrog:docs/fix-autosummary-methods

Conversation

@astrofrog

Copy link
Copy Markdown
Member

@astrofrog

Copy link
Copy Markdown
Member Author

I think the solution is going to have to involve customizing the class.rst template. We might have to change

.. automethod:: __init__

to

{% for item in methods %}
.. automethod:: {{ name }}.{{ item }}
{%- endfor %}

though we may want the method docstrings to be below the autosummary table. I wasn't sure what the best way to specify a custom template directory - @eteq, any suggestions?

For info, the default class.rst template is:

{{ fullname }}
{{ underline }}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}

   {% block methods %}
   .. automethod:: __init__

   {% if methods %}
   .. rubric:: Methods

   .. autosummary::
   {% for item in methods %}
      ~{{ name }}.{{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

   {% block attributes %}
   {% if attributes %}
   .. rubric:: Attributes

   .. autosummary::
   {% for item in attributes %}
      ~{{ name }}.{{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

which explains why only __init__ had a docstring.

@ghost ghost assigned astrofrog May 23, 2012
@astrofrog

Copy link
Copy Markdown
Member Author

I've figured out a solution and will attach code shortly

@astrofrog

Copy link
Copy Markdown
Member Author

Attached is a fix. A couple of questions for @mdboom and @eteq:

  • Did we agree that __init__ should actually be documented in the class docstring? If so, then I can remove init from the table (I have a local copy that does that) and I'll have to reflect AstropyLogger to reflect that
  • Is it ok to have attributes come first like I've done it? They got kind of lost if they were after the methods section, and it didn't make much sense to have the summary of methods, attributes, and then the detailed methods.

@astrofrog

Copy link
Copy Markdown
Member Author

Also, please check the fix to ensure that it works for you!

@astrofrog

Copy link
Copy Markdown
Member Author

I figured out how to automatically include reference files at the top of generated documentation, and have attached it here (see commit message for more details). Let me know if you have any suggestions.

@mdboom - could you test this out with vo and wcs?

@astrofrog

Copy link
Copy Markdown
Member Author

@eteq - just to check, any objections to me merging this?

Comment thread astropy/sphinx/ext/automodsumm.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand why you made this change... shouldn't .rst files be in docs/autsummary rather than in the source tree? Thats my understanding of how autosummary works (although I admit I haven't yet tested it)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, the base templates are in sphinx/ext/autosummary/templates in the sphinx package, so I wanted to mirror that. I tried for hours to get it to work by having the templates in docs/templates, but failed. This was the cleanest and easiest in the end.

If you figure out how to do it with docs/templates let me know though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify what I said above - the templates were originally in the sphinx source tree, so it turned out the easiest thing to do was just move them to our source tree rather than try and have a mechanism for specifying custom templates. If you look here you'll see that there is no mechanism for adding custom templates if a builder is specified (which it is) so if we wanted to have a mechanism to replace the autosummary templates, we'd have to implement it (hence why the above was simpler). It's just the only way I could figure out without more extensive changes to the template infrastructure in this file. I might be wrong though!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will look into this. I have a vague memory of encountering a way to do this while writing automodsumm, but I'll have to investigate it further. (It doesn't necessarily block this PR given that it works right now as-is, though, so if I don't get to this soon enough, I can do it as a separate PR of astropy.)

@eteq

eteq commented May 24, 2012

Copy link
Copy Markdown
Member

I also agree that it makes sense to remove __init__ from the list - our documentation standard says you document init in the class documentation, not in __init__ itself. I also like the "attributes come first" scheme.

@eteq

eteq commented May 24, 2012

Copy link
Copy Markdown
Member

Regarding the references: I'm a little hesitant to force the docs structure to parallel the source structure - that seems rather restrictive and could lead to much confusion. Maybe instead include an additional option to automodsumm that can be used to specify where the references file can be found? @mdboom - would that work for you?

@astrofrog

Copy link
Copy Markdown
Member Author

@eteq - agree with the option idea, that would indeed be less restrictive. I do think that the docs should mirror the code structure better than they do at the moment (e.g. we should have docs/io, but I agree that we don't necessarily want to make it compulsory).

@astrofrog

Copy link
Copy Markdown
Member Author

@eteq - how do you think we should proceed for this? I agree a :references: attribute would be nice, but I had trouble implementing it in practice as I'm not sure I understand all the subtleties of autosummary.

@eteq

eteq commented May 30, 2012

Copy link
Copy Markdown
Member

@astrofrog - I'm not sure if "subtleties" is so much it as "confusingness" :) I haven't had a chance to look at this, as I was very busy last week, but I should be able to either implement this or judge it "unimplementable" by Friday.

@astrofrog

Copy link
Copy Markdown
Member Author

Ok - sounds good. I will merge this tonight if you don't get :references: to work, and we can always work on that more in future (the current code is not ideal, but not that bad at the same time - it doesn't require the docs to mirror the package structure, it just requires a reference file be placed in a location that mirrors the package structure if references are desired. If no references are needed, then the docs can be anywhere).

@mdboom

mdboom commented Jun 1, 2012

Copy link
Copy Markdown
Contributor

Personally, I think keeping the docs mirroring the source is a minor inconvenience and in some ways a nice thing. Adding the :references: feature adds complication that needs to be maintained. Just my 2c. Maybe I'm still jaded by maintaining the matplotlib plot-directive to work under multiple versions of Sphinx and what a pain that has been ;)

@eteq

eteq commented Jun 2, 2012

Copy link
Copy Markdown
Member

I'm looking at this now, so depending on what timezone "tonight" means, please hold off for just abit on merging, @astrofrog . And I see your point, @mdboom - it depends on just how complicated in ends up having to be.

@eteq

eteq commented Jun 2, 2012

Copy link
Copy Markdown
Member

Alright, I think I could implement the :references: feature, but it's not trivial. Given what @mdboom said, with that in mind, I'm fine with just waiting until later if it becomes more useful, as @astrofrog suggests.

Also, @astrofrog , there's a PR astrofrog#12 that addresses the template location issue (and #243 as a bonus).

astrofrog and others added 6 commits June 2, 2012 10:52
…rated docs. If the module is a directory, e.g. astropy.wcs, then the reference file should be in docs/wcs/references.txt, while if the module is a file, e.g. astropy.config.logging_helper then the reference file is in docs/config/references.txt
@astrofrog

Copy link
Copy Markdown
Member Author

Ok, I merged in your PR and have also removed __init__ from the method list as we discussed before, so I'll merge this in.

astrofrog added a commit that referenced this pull request Jun 2, 2012
Docstrings for methods are missing in generated docs
@astrofrog
astrofrog merged commit c46cd01 into astropy:master Jun 2, 2012
@astrofrog

Copy link
Copy Markdown
Member Author

@eteq - for some reason, the docs on readthedocs don't reflect the template change - any ideas?

@astrofrog

Copy link
Copy Markdown
Member Author

@eteq - I think it's a cache problem, I added the logging docs back (they had disappeared due to the move) and those are ok, but other generated pages are not. I'll see if we can make a clean build.

@eteq

eteq commented Jun 2, 2012

Copy link
Copy Markdown
Member

@eteq

eteq commented Jun 2, 2012

Copy link
Copy Markdown
Member

@astrofrog

Copy link
Copy Markdown
Member Author

Ok, it seems to be fixed now - I had opened an issue with readthedocs, so maybe they did just that. Good to know for future!

@eteq

eteq commented Jun 2, 2012

Copy link
Copy Markdown
Member

Actually, I did it just now because I discovered you can just go to that address with a regular webbrowser and click a button to do the wipe. If you ever need to do this in the future, note that you have to manually trigger a new build after the wipe.

@astrofrog

Copy link
Copy Markdown
Member Author

Ok, awesome! I'll close the issue with readthedocs.

keflavich pushed a commit to keflavich/astropy that referenced this pull request Oct 9, 2013
…thods

Docstrings for methods are missing in generated docs
@astrofrog
astrofrog deleted the docs/fix-autosummary-methods branch July 5, 2016 18:46
astrofrog added a commit to astropy/sphinx-automodapi that referenced this pull request Jan 27, 2018
…mmary-methods

Docstrings for methods are missing in generated docs
astrofrog pushed a commit to astrofrog/astropy that referenced this pull request Jun 12, 2019
jeffjennings pushed a commit to jeffjennings/astropy that referenced this pull request Jul 2, 2025
Adding dust_extinction package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants