Port python modules documentation to Py 3.11

Fixes #14148: Automatic python modules documentation index page broken
This commit is contained in:
wmayer
2024-05-23 23:52:47 +02:00
committed by wwmayer
parent b0acb563ea
commit 9b0026bbe1
2 changed files with 47 additions and 3 deletions

View File

@@ -28,18 +28,20 @@ class FreeCADDoc(pydoc.HTMLDoc):
modpkgs.sort()
contents = self.multicolumn(modpkgs, self.modpkglink)
return self.bigsection(dir, '#ffffff', '#ee77aa', contents)
try:
return self.bigsection(dir, '#ffffff', '#ee77aa', contents)
except Exception as e:
return self.bigsection(dir, 'pkg-content', contents)
def bltinlink(name):
return '<a href=\"%s.html\">%s</a>' % (name, name)
def createDocumentation():
def getIndexOld():
pydoc.html = FreeCADDoc()
title = 'FreeCAD Python Modules Index'
heading = pydoc.html.heading('<big><big><strong>Python: Index of Modules</strong></big></big>','#ffffff', '#7799ee')
names = list(filter(lambda x: x != '__main__', sys.builtin_module_names))
contents = pydoc.html.multicolumn(names, bltinlink)
indices = ['<p>' + pydoc.html.bigsection('Built-in Modules', '#ffffff', '#ee77aa', contents)]
@@ -61,3 +63,44 @@ pydoc</strong> by Ka-Ping Yee &lt;ping@lfw.org&gt;</font>'''
htmldocument = pydoc.html.page(title, contents)
return htmldocument
def getIndexNew():
pydoc.html = FreeCADDoc()
title = 'FreeCAD Python Modules Index'
heading = pydoc.html.heading(
'<strong class="title">Index of Modules</strong>'
)
names = list(filter(lambda x: x != '__main__', sys.builtin_module_names))
contents = pydoc.html.multicolumn(names, bltinlink)
indices = ['<p>' + pydoc.html.bigsection('Built-in Modules', 'index', contents)]
names = ['FreeCAD', 'FreeCADGui']
contents = pydoc.html.multicolumn(names, bltinlink)
indices.append('<p>' + pydoc.html.bigsection('Built-in FreeCAD Modules', 'index', contents))
seen = {}
for dir in sys.path:
dir = os.path.realpath(dir)
ret = pydoc.html.index(dir, seen)
if ret != None:
indices.append(ret)
contents = heading + ' '.join(indices) + '''<p align=right>
<font color=\"#909090\" face=\"helvetica, arial\"><strong>
pydoc</strong> by Ka-Ping Yee &lt;ping@lfw.org&gt;</font>'''
htmldocument = pydoc.html.page(title, contents)
return htmldocument
def getIndex():
try:
return getIndexOld()
except Exception as e:
return getIndexNew()
def getPage(page):
object, name = pydoc.resolve(page)
page = pydoc.html.page(pydoc.describe(object), pydoc.html.document(object, name))
return page

View File

@@ -122,6 +122,7 @@ QByteArray PythonOnlineHelp::invoke(const std::function<std::string(Py::Module&)
catch (const Py::Exception&) {
// load the error page
Base::PyException e;
e.ReportException();
return loadFailed(QString::fromUtf8(e.what()));
}
}