Skip to content

Commit

Permalink
docs: document embed() under IPython
Browse files Browse the repository at this point in the history
The narrative documentation refers to embed() as IPython.embed(), but
this function is not documented under the IPython module in the API
docs, it is under IPython.terminal.embed. This is because IPython is not
listed in the __names_from_all__ list in autogen_api.py, so only
functions defined directly in IPython/__init__.py are listed, and
embed() is _imported_ there from IPython.terminal.embed.

Add the documentation of embed directly under the IPython module by
adding 'IPython' to the __names_from_all__ list. Note that we avoid
excluding IPython.terminal.embed in the lists of patterns to skip since
we still want to document the rest of the names in this module. Note
also that darker insists on reformatting this list.

Add an explicit __all__ list in IPython/__init__.py, listing the
currently documented functions as well as embed().

Finally, tweak the embed() docstring to refer explicitely to
terminal.embed.InteractiveShellEmbed so that these links keep working.
  • Loading branch information
phil-blain committed Mar 25, 2023
1 parent 1d7eee5 commit 853291b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions IPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
from .utils.sysinfo import sys_info
from .utils.frame import extract_module_locals

__all__ = ["start_ipython", "embed", "start_kernel", "embed_kernel"]

# Release data
__author__ = '%s <%s>' % (release.author, release.author_email)
__license__ = release.license
Expand Down
8 changes: 4 additions & 4 deletions IPython/terminal/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def mainloop(
def embed(*, header="", compile_flags=None, **kwargs):
"""Call this to embed IPython at the current point in your program.
The first invocation of this will create an :class:`InteractiveShellEmbed`
The first invocation of this will create a :class:`terminal.embed.InteractiveShellEmbed`
instance and then call it. Consecutive calls just call the already
created instance.
Expand All @@ -375,10 +375,10 @@ def embed(*, header="", compile_flags=None, **kwargs):
header : str
Optional header string to print at startup.
compile_flags
Passed to the `compile_flags` parameter of :py:meth:`InteractiveShellEmbed.mainloop()`,
which is called when the :class:`InteractiveShellEmbed` instance is called.
Passed to the `compile_flags` parameter of :py:meth:`terminal.embed.InteractiveShellEmbed.mainloop()`,
which is called when the :class:`terminal.embed.InteractiveShellEmbed` instance is called.
**kwargs : various, optional
Any other kwargs will be passed to the :class:`InteractiveShellEmbed` constructor.
Any other kwargs will be passed to the :class:`terminal.embed.InteractiveShellEmbed` constructor.
Full customization can be done by passing a traitlets :class:`Config` in as the
`config` argument (see :ref:`configure_start_ipython` and :ref:`terminal_options`).
"""
Expand Down
11 changes: 7 additions & 4 deletions docs/autogen_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@
# them as part of the public API. They must have __all__ defined. The
# non-API modules they import from should be excluded by the skip patterns
# above.
docwriter.names_from__all__.update({
'IPython.display',
})

docwriter.names_from__all__.update(
{
"IPython",
"IPython.display",
}
)

# Now, generate the outputs
docwriter.write_api_docs(outdir)
# Write index with .txt extension - we can include it, but Sphinx won't try
Expand Down

0 comments on commit 853291b

Please sign in to comment.