Skip to content

Commit

Permalink
Port python modules documentation to Py 3.11
Browse files Browse the repository at this point in the history
Fixes #14148: Automatic python modules documentation index page broken
  • Loading branch information
wwmayer committed May 24, 2024
1 parent b0acb56 commit 9b0026b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
49 changes: 46 additions & 3 deletions src/Ext/freecad/freecad_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ def index(self, dir, shadowed=None):

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:

Check warning on line 33 in src/Ext/freecad/freecad_doc.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Catching too general exception Exception (broad-exception-caught)

Check warning on line 33 in src/Ext/freecad/freecad_doc.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Unused variable 'e' (unused-variable)
return self.bigsection(dir, 'pkg-content', contents)

def bltinlink(name):
return '<a href=\"%s.html\">%s</a>' % (name, name)

Check warning on line 37 in src/Ext/freecad/freecad_doc.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Formatting a regular string which could be an f-string (consider-using-f-string)

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

Check warning on line 43 in src/Ext/freecad/freecad_doc.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (120/100) (line-too-long)


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)]
Expand All @@ -61,3 +63,44 @@ def createDocumentation():

htmldocument = pydoc.html.page(title, contents)
return htmldocument

def getIndexNew():
pydoc.html = FreeCADDoc()
title = 'FreeCAD Python Modules Index'

heading = pydoc.html.heading(

Check failure on line 71 in src/Ext/freecad/freecad_doc.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

No value for argument 'fgcol' in method call (no-value-for-parameter)

Check failure on line 71 in src/Ext/freecad/freecad_doc.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

No value for argument 'bgcol' in method call (no-value-for-parameter)
'<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
1 change: 1 addition & 0 deletions src/Gui/OnlineDocumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check warning on line 124 in src/Gui/OnlineDocumentation.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable name 'e' is too short, expected at least 2 characters [readability-identifier-length]
e.ReportException();
return loadFailed(QString::fromUtf8(e.what()));
}
}
Expand Down

0 comments on commit 9b0026b

Please sign in to comment.