astropy / sphinx-automodapi

Sphinx extension for generating API documentation
https://sphinx-automodapi.readthedocs.io
BSD 3-Clause "New" or "Revised" License
63 stars 45 forks source link

Customize the code block used for code examples #151

Closed pharmpy-dev-123 closed 2 years ago

pharmpy-dev-123 commented 2 years ago

Is it possible to customize the generated code blocks used for code examples? I want to use my own directive which does some approximate Python to R transpilation of code examples.

pllim commented 2 years ago

astropy uses directives like this but I don't remember what is the machinery used to extract them. Maybe @jonathansick knows?

.. EXAMPLE START: 

Some narrative with code blocks.

.. EXAMPLE END
pllim commented 2 years ago

As for custom directive or Python to R, that is currently out of scope for this repository.

pharmpy-dev-123 commented 2 years ago

As for custom directive or Python to R, that is currently out of scope for this repository.

I am developing such a custom directive. I would like to use it instead of the one used by default by automodapi.

astrofrog commented 2 years ago

@pharmpy-dev-123 does sphinx-automodapi hard-code this? I thought it just reproduced whatever was in docstrings, so if you use your custom directive in there it should work?

pharmpy-dev-123 commented 2 years ago

@astrofrog Haha! You mean there would be a way for me to specify this in the docstrings. Currently, most of my existing docstrings use a declarative Example section instead of using a Sphinx directive. Let me see what I can do.

pharmpy-dev-123 commented 2 years ago

@astrofrog I definitely want to keep the Example(s) sections using declarative doctest blocks. I do not want to write explicit Sphinx directives in there. The question then is whether I can tell Sphinx or this extension to use a custom code-block for doctest blocks.

astrofrog commented 2 years ago

@pharmpy-dev-123 that is a good question, but in fact Sphinx-automodapi doesn't actually interpret the docstrings or know about example sections (we just put autodoc directives in the API docs) - often we use a package such as numpydoc or napoleon to render the content of the docstrings - if you are using one of those packages that might be the right place to have an option for what you need.

pharmpy-dev-123 commented 2 years ago

@astrofrog Makes sense. Thanks!