From 9b0026bbe149d778cbeabc79d14cb7b122e3b497 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 23 May 2024 23:52:47 +0200 Subject: [PATCH] Port python modules documentation to Py 3.11 Fixes #14148: Automatic python modules documentation index page broken --- src/Ext/freecad/freecad_doc.py | 49 +++++++++++++++++++++++++++++++-- src/Gui/OnlineDocumentation.cpp | 1 + 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Ext/freecad/freecad_doc.py b/src/Ext/freecad/freecad_doc.py index 8ca2bb2b7c..b6049fe412 100644 --- a/src/Ext/freecad/freecad_doc.py +++ b/src/Ext/freecad/freecad_doc.py @@ -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 '%s' % (name, name) -def createDocumentation(): +def getIndexOld(): pydoc.html = FreeCADDoc() title = 'FreeCAD Python Modules Index' heading = pydoc.html.heading('Python: Index of Modules','#ffffff', '#7799ee') - names = list(filter(lambda x: x != '__main__', sys.builtin_module_names)) contents = pydoc.html.multicolumn(names, bltinlink) indices = ['

' + pydoc.html.bigsection('Built-in Modules', '#ffffff', '#ee77aa', contents)] @@ -61,3 +63,44 @@ pydoc by Ka-Ping Yee <ping@lfw.org>''' htmldocument = pydoc.html.page(title, contents) return htmldocument + +def getIndexNew(): + pydoc.html = FreeCADDoc() + title = 'FreeCAD Python Modules Index' + + heading = pydoc.html.heading( + 'Index of Modules' + ) + + names = list(filter(lambda x: x != '__main__', sys.builtin_module_names)) + contents = pydoc.html.multicolumn(names, bltinlink) + indices = ['

' + pydoc.html.bigsection('Built-in Modules', 'index', contents)] + + names = ['FreeCAD', 'FreeCADGui'] + contents = pydoc.html.multicolumn(names, bltinlink) + indices.append('

' + 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) + '''

+ +pydoc by Ka-Ping Yee <ping@lfw.org>''' + + 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 diff --git a/src/Gui/OnlineDocumentation.cpp b/src/Gui/OnlineDocumentation.cpp index e6c70cfb93..51d036abee 100644 --- a/src/Gui/OnlineDocumentation.cpp +++ b/src/Gui/OnlineDocumentation.cpp @@ -122,6 +122,7 @@ QByteArray PythonOnlineHelp::invoke(const std::function