-
Notifications
You must be signed in to change notification settings - Fork 48
Custom docstring section #2
Comments
I'm also looking into this. We have a class that uses environment variables and we are not sure what section to use to document that. |
The code has a mechanism for custom sections. I'm not sure how to use it as it doesn't seem to be documented. But why not just have a flag to allow arbitrary section headers, instead of just the pre-allowed ones? Based on my reading of the code, this should be trivial to implement. |
I found this in the docs for Napoleon: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/sphinxcontrib.napoleon.html#sphinxcontrib.napoleon.Config.napoleon_custom_sections But I can't seem to get it working. In my function's docstring, I have:
In conf.py, I added My rendered doc page ends up looking like this: https://i.imgur.com/kmLj1wG.png |
I figured out that ReadTheDocs was using an old version of Sphinx from before Napoleon supported this option. I added a requirements.txt file to the base of my repo with one entry in it: Now the This is my docstring right now:
Is there a way to make it look more consistent with the Parameters section? |
Yes, you can, by adding And this is exactly why I was coming over here, since I was having some problems with this. |
Exactly as @1313e said. Is there an update on this? Having the title being a custom one and meanwhile the format being the aliased section's would be really nice. |
Ditto |
I have a similar desire and face the same problem that @1313e pointed out:
It will be really helpful if we can customize the custom sections a bit more.The following setting has a similar effect, but it renders the Parameters name instead of the custom name.
The following link includes more details about the solutions: |
Hi @RobRuana. I am willing to provide a PR that creates a configurable custom docstring section. Will you be interested in it? If so, do you prefer any of the proposed solutions that I comment on above? Thanks! |
FYI: sphinx-doc/sphinx#8658 adds the feature discussed here to the Napoleon extension that comes with sphinx, and has been merged. Kudos to @SolidifiedRay for providing the patch! |
When exactly would that be available in Sphinx, if you know the answer of course? |
Unfortunately I don't, but looking at the release cadence I suppose fairly soon? (cc @tk0miya, the maintainer who merged the feature). |
The release cycle of Sphinx is every other month. So it will be released in Feb (maybe mid of Feb). |
@SolidifiedRay big thanks for the work you have done to add this feature (thanks also to @tk0miya and @lukpueh). I looked to see if It was possible to add custom section similar to the Parameters one but with a custom name and now it's possible ! For people on the internet who are looking for the same thing, to add a custom section named "Data Inputs" which behaves like the parameters section, add this in your napoleon_custom_sections = [('Data Inputs', 'params_style')] Now you can add something like this in your docstrings : Data Inputs:
param1 (int): Info on the first data parameter.
param2 (str): Details on the second data parameter. In case this didn't work for you this is the versions of my packages: Sphinx==3.5.4
sphinxcontrib-apidoc==0.3.0
sphinxcontrib-napoleon==0.7 |
I would like to see this functionality extended to class-level docstrings (see #33), particularly enabling developers to document class variables (e.g. |
For additional reference, please see this SO question. Simply using an |
Is it possible to add a custom docstring section? I sometimes need to add a section with different name which is not listed in allowed section headers. When I run sphinx, the section header is deleted from the result.
The text was updated successfully, but these errors were encountered: