mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
display link to module docs when it looks like the object module is a core
module
This commit is contained in:
parent
0d6e8cde1a
commit
4997a69fe4
1 changed files with 47 additions and 1 deletions
48
Lib/pydoc.py
48
Lib/pydoc.py
|
@ -24,6 +24,14 @@ and also pops up a little window for controlling it.
|
||||||
|
|
||||||
Run "pydoc -w <name>" to write out the HTML documentation for a module
|
Run "pydoc -w <name>" to write out the HTML documentation for a module
|
||||||
to a file named "<name>.html".
|
to a file named "<name>.html".
|
||||||
|
|
||||||
|
Module docs for core modules are assumed to be in
|
||||||
|
|
||||||
|
http://www.python.org/doc/current/lib/
|
||||||
|
|
||||||
|
This can be overridden by setting the PYTHONDOCS environment variable
|
||||||
|
to a different URL or to a local directory containing the Library
|
||||||
|
Reference Manual pages.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = "Ka-Ping Yee <ping@lfw.org>"
|
__author__ = "Ka-Ping Yee <ping@lfw.org>"
|
||||||
|
@ -295,6 +303,33 @@ class Doc:
|
||||||
|
|
||||||
docmodule = docclass = docroutine = docother = fail
|
docmodule = docclass = docroutine = docother = fail
|
||||||
|
|
||||||
|
def getdocloc(self, object):
|
||||||
|
"""Return the location of module docs or None"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
file = inspect.getabsfile(object)
|
||||||
|
except TypeError:
|
||||||
|
file = '(built-in)'
|
||||||
|
|
||||||
|
docloc = os.environ.get("PYTHONDOCS",
|
||||||
|
"http://www.python.org/doc/current/lib")
|
||||||
|
basedir = os.path.join(sys.exec_prefix, "lib",
|
||||||
|
"python"+sys.version[0:3])
|
||||||
|
if (isinstance(object, type(os)) and
|
||||||
|
(object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
|
||||||
|
'marshal', 'posix', 'signal', 'sys',
|
||||||
|
'thread', 'zipimport') or
|
||||||
|
(file.startswith(basedir) and
|
||||||
|
not file.startswith(os.path.join(basedir, 'site-packages'))))):
|
||||||
|
if docloc.startswith("http://"):
|
||||||
|
docloc = (docloc.rstrip("/") +
|
||||||
|
"/module-%s.html" % object.__name__)
|
||||||
|
else:
|
||||||
|
docloc = os.path.join(docloc, "module-%s.html" % name)
|
||||||
|
else:
|
||||||
|
docloc = None
|
||||||
|
return docloc
|
||||||
|
|
||||||
# -------------------------------------------- HTML documentation generator
|
# -------------------------------------------- HTML documentation generator
|
||||||
|
|
||||||
class HTMLRepr(Repr):
|
class HTMLRepr(Repr):
|
||||||
|
@ -535,8 +570,14 @@ class HTMLDoc(Doc):
|
||||||
info.append(self.escape(str(object.__date__)))
|
info.append(self.escape(str(object.__date__)))
|
||||||
if info:
|
if info:
|
||||||
head = head + ' (%s)' % join(info, ', ')
|
head = head + ' (%s)' % join(info, ', ')
|
||||||
|
docloc = self.getdocloc(object)
|
||||||
|
if docloc is not None:
|
||||||
|
docloc = '<br><a href="%(docloc)s">Module Docs</a>' % locals()
|
||||||
|
else:
|
||||||
|
docloc = ''
|
||||||
result = self.heading(
|
result = self.heading(
|
||||||
head, '#ffffff', '#7799ee', '<a href=".">index</a><br>' + filelink)
|
head, '#ffffff', '#7799ee',
|
||||||
|
'<a href=".">index</a><br>' + filelink + docloc)
|
||||||
|
|
||||||
modules = inspect.getmembers(object, inspect.ismodule)
|
modules = inspect.getmembers(object, inspect.ismodule)
|
||||||
|
|
||||||
|
@ -950,6 +991,11 @@ class TextDoc(Doc):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
file = '(built-in)'
|
file = '(built-in)'
|
||||||
result = result + self.section('FILE', file)
|
result = result + self.section('FILE', file)
|
||||||
|
|
||||||
|
docloc = self.getdocloc(object)
|
||||||
|
if docloc is not None:
|
||||||
|
result = result + self.section('MODULE DOCS', docloc)
|
||||||
|
|
||||||
if desc:
|
if desc:
|
||||||
result = result + self.section('DESCRIPTION', desc)
|
result = result + self.section('DESCRIPTION', desc)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue