Description
When converting rST projects to use MyST, directives from sphinx.ext.autodoc's such as automodule
can cause issues.
The sphinx extension sphinx.ext.autodoc provides directives (automodule
, autoclass
, ...) that emits rST like .. py:module:: kubespawner.utils
and provides the directives with raw docstrings from the referenced Python code.
Background
Here is an example of how you would use sphinx.ext.autodoc from a MyST document correctly.
# Utilities
```{eval-rst}
.. automodule:: kubespawner.utils
```
The automodule directive will emit rST directives and raw docstrings that also ends up parsed as rST.
Two issues
Here is an example using the automodule
directly as a MyST directive, and it leads to two issues:
# Utilities
```{automodule} kubespawner.utils
```
Issue 1 - sphinx.ext.autodoc emits rST formatted directives
sphinx.ext.autodoc will emit rST formatted directives even though invoked from a MyST document like:
# Utilities
```{automodule} kubespawner.utils
```
Issue 2 - sphinx.ext.autodoc has made us write docstrings with rST
A project who has used sphinx.ext.autodoc has needed to write the docstrings in rST rather than MyST historically due to always being parsed with rST.
If we are to support MyST docstrings, I think of one initial key goal, and a stretch goal:
- Key goal: to support a project wide default declaring docstrings to be either rST or MyST (100% rST docstrings or 100% MyST docstrings).
- Stretch goal: to support exceptions from the default in some way, using both rST and MyST docstrings.
I see the key goal as a very valuable goal resolving my its own, and the stretch goal as valuable but also likely more complicated to implement and use sustainably.
Ideas to address this
I'm not sure if and how to address these issues. I've opened this issue to brainstorm if we can find reasonable resolutions to these issues - especially if we can find a way to support 100% MyST based docstrings via sphinx.ext.autodoc. A solution that is too complicated and hard to maintain isn't worth developing in my mind.
Support directly in sphinx.ext.autodoc?
Maybe sphinx.ext.autodoc could add support for this directly?
- sphix.ext.autodoc should somehow decide if it should emit rST or MyST directives, either by configuration or automatic detection.
- sphinx.ext.autodoc could optionally also wrap the raw docstring in a directive like eval-rst based on configuraition
Support by wrapping or patching sphinx.ext.autodoc in another sphinx extension?
Maybe a sphinx extension could be created (myst-autodoc), which would patch or influence sphinx.ext.autodoc somehow. Maybe by wrapping/redefining the provided directives and running rst2myst on the old definition, or maybe patching some functions in sphinx.ext.autodoc?
Your ideas?
I opened this issue hoping to overview the situation and find actionable paths towards resolving this in a good way that is sutainable to maintain and use.