Skip to content

Commit

Permalink
Backport PR ipython#13503: Update sphinxify usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau authored and meeseeksmachine committed Feb 1, 2022
1 parent 2f7b0e5 commit 1d78139
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions IPython/core/interactiveshell.py
Expand Up @@ -93,12 +93,17 @@
try:
import docrepr.sphinxify as sphx

def sphinxify(doc):
with TemporaryDirectory() as dirname:
return {
'text/html': sphx.sphinxify(doc, dirname),
'text/plain': doc
}
def sphinxify(oinfo):
wrapped_docstring = sphx.wrap_main_docstring(oinfo)

def sphinxify_docstring(docstring):
with TemporaryDirectory() as dirname:
return {
"text/html": sphx.sphinxify(wrapped_docstring, dirname),
"text/plain": docstring,
}

return sphinxify_docstring
except ImportError:
sphinxify = None

Expand Down Expand Up @@ -919,7 +924,7 @@ def init_virtualenv(self):
while p.is_symlink():
p = Path(os.readlink(p))
paths.append(p.resolve())

# In Cygwin paths like "c:\..." and '\cygdrive\c\...' are possible
if p_venv.parts[1] == "cygdrive":
drive_name = p_venv.parts[2]
Expand Down Expand Up @@ -1765,7 +1770,9 @@ def _inspect(self, meth, oname, namespaces=None, **kw):
This function is meant to be called by pdef, pdoc & friends.
"""
info = self._object_find(oname, namespaces)
docformat = sphinxify if self.sphinxify_docstring else None
docformat = (
sphinxify(self.object_inspect(oname)) if self.sphinxify_docstring else None
)
if info.found:
pmethod = getattr(self.inspector, meth)
# TODO: only apply format_screen to the plain/text repr of the mime
Expand Down Expand Up @@ -1812,7 +1819,11 @@ def object_inspect_mime(self, oname, detail_level=0):
with self.builtin_trap:
info = self._object_find(oname)
if info.found:
docformat = sphinxify if self.sphinxify_docstring else None
docformat = (
sphinxify(self.object_inspect(oname))
if self.sphinxify_docstring
else None
)
return self.inspector._get_info(
info.obj,
oname,
Expand Down

0 comments on commit 1d78139

Please sign in to comment.