-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Parameter Names and Types are Displayed Wrong in Docs #468
Comments
… generation parser. Fixes edgi-govdata-archiving#468
Update: the solution described above is completely wrong. 🙁 What’s actually happening here appears to be an incompatibility between Sphinx v2 and the sphinx_rtd_theme plugin. Numpydoc is still doing the right thing, and there are no changes or issues with how our actual docstrings are getting parsed. You can skip to the conclusion at the bottom, but if you want a full overview of what’s broken, read along with my journey into our docs tooling… Some Background on Our Doc Build ToolsThis was a journey — I’ve never dug into Sphinx before, and there are a bunch of pieces to making this work.
So the docs pipeline when you run
Why the Proposed Fix Above is WrongBased on the above, there are a few points where things could be going wrong.
So the actual problem here is a mix of 4 (how Sphinx renders HTML fragments from .rst) and 3 (how sphinx_rtd_theme formats and styles those fragments). More importantly, the issue is clearly not 1 (Numpy), so changing our docstrings isn’t the right solution. In fact, changing the docstrings to remove the space between the parameter name and colon as described in the original post will make the colon show up in the docs, but makes the underlying problem worse. Take the docstring for web-monitoring-processing/web_monitoring/db.py Lines 562 to 578 in 803af96
Numpy parses it to .rst like so: List Changes between two Versions on a Page.
:Parameters:
**page_id** : string
..
**include_total** : boolean, optional
Whether to include a `meta.total_results` field in the response.
If not set, `links.last` will usually be empty unless you are on
the last chunk. Setting this option runs a pretty expensive query,
so use it sparingly. (Default: False)
:Returns:
**response** : dict
.. And if we remove the space between parameter name and the colon, it parses like this: List Changes between two Versions on a Page.
:Parameters:
**page_id: string**
..
**include_total: boolean, optional**
Whether to include a `meta.total_results` field in the response.
If not set, `links.last` will usually be empty unless you are on
the last chunk. Setting this option runs a pretty expensive query,
so use it sparingly. (Default: False)
:Returns:
**response: dict**
.. The parameters in both cases are definition lists. Definition lists in .rst get converted to So what’s the real problem and what should we actually be doing? Conclusion (TL;DR)The real issue is that Sphinx v1 and v2 render reStructedText field lists and definition lists in very different ways, and sphinx_rtd_theme is designed to work with the way v1 did it:
So! The basic solution here is to add some extra CSS to our output (or just to downgrade to Sphinx v1). Read The Docs has some info on this: https://docs.readthedocs.io/en/latest/guides/adding-custom-css.html We need to add the Relevant issues at other projects:
|
…isfy doc generation parser. Fixes edgi-govdata-archiving#468" This reverts commit 70f4fd5.
The Read-the-Docs theme we use for our docs is not yet totally compatible with Sphinx v2, and causes a function’s parameter name and types to get smushed together and look confusing. This adds some custom CSS to fix that up. Fixes #468.
@Mr0grog Thank you for detailed explanation. I have sphinx 3.2.0, sphinx-rtd-theme 0.5.0 installed, still for field list like I want to achieve this style as show in sphinx-rtd-theme documentation page: Can you provide any insights on what could be wrong on my settings? Thanks 🙏 |
I was able to solve it using some hack of css |
In a recent Sphinx or Numpydoc update, our docs stopped differentiating between a method’s parameters and their types, so they get joined up with no spaces in the display:
They used to display like this:
(Updated 2019-10-04 to cross out the incorrect analysis below. See the first comment (#468 (comment)) for correct info.)
Old, incorrect analysis:
We think there was an update that switched the parameter documentation style from:To:Note the missing space between the parameter name and the colon. So we probably just need to update all the docstrings throughout the codebase to remove those spaces.The text was updated successfully, but these errors were encountered: