| 
23 | 23 | copy_strip - Copy the text part of idle.html to help.html while rstripping each line.  | 
24 | 24 | 
  | 
25 | 25 | show_idlehelp - Create HelpWindow.  Called in EditorWindow.help_dialog.  | 
 | 26 | +
  | 
 | 27 | +_get_dochome() - Return path to docs on user's system if present,  | 
 | 28 | +otherwise return link to docs.python.org.  | 
26 | 29 | """  | 
 | 30 | +import os  | 
 | 31 | +import sys  | 
27 | 32 | from html.parser import HTMLParser  | 
28 | 33 | from os.path import abspath, dirname, isfile, join  | 
29 | 34 | from platform import python_version  | 
@@ -289,6 +294,47 @@ def show_idlehelp(parent):  | 
289 | 294 |     return HelpWindow(parent, filename, 'IDLE Doc (%s)' % python_version())  | 
290 | 295 | 
 
  | 
291 | 296 | 
 
  | 
 | 297 | +def _get_dochome():  | 
 | 298 | +    "Return path to local docs if present, otherwise link to docs.python.org."  | 
 | 299 | + | 
 | 300 | +    dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html')  | 
 | 301 | +    if sys.platform.count('linux'):  | 
 | 302 | +        # look for html docs in a couple of standard places  | 
 | 303 | +        pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3]  | 
 | 304 | +        if os.path.isdir('/var/www/html/python/'):  # rpm package manager  | 
 | 305 | +            dochome = '/var/www/html/python/index.html'  | 
 | 306 | +        else:  | 
 | 307 | +            basepath = '/usr/share/doc/'  # dnf/apt package managers  | 
 | 308 | +            dochome = os.path.join(basepath, pyver, 'Doc', 'index.html')  | 
 | 309 | + | 
 | 310 | +    elif sys.platform[:3] == 'win':  | 
 | 311 | +        import winreg  # Windows only, block only executed once.  | 
 | 312 | +        docfile = ''  | 
 | 313 | +        KEY = (rf"Software\Python\PythonCore\{sys.winver}"  | 
 | 314 | +               r"\Help\Main Python Documentation")  | 
 | 315 | +        try:  | 
 | 316 | +            docfile = winreg.QueryValue(winreg.HKEY_CURRENT_USER, KEY)  | 
 | 317 | +        except FileNotFoundError:  | 
 | 318 | +            try:  | 
 | 319 | +                docfile = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, KEY)  | 
 | 320 | +            except FileNotFoundError:  | 
 | 321 | +                pass  | 
 | 322 | +        if os.path.isfile(docfile):  | 
 | 323 | +            dochome = docfile  | 
 | 324 | +    elif sys.platform == 'darwin':  | 
 | 325 | +        # documentation may be stored inside a python framework  | 
 | 326 | +        dochome = os.path.join(sys.base_prefix,  | 
 | 327 | +                               'Resources/English.lproj/Documentation/index.html')  | 
 | 328 | +    dochome = os.path.normpath(dochome)  | 
 | 329 | +    if os.path.isfile(dochome):  | 
 | 330 | +        if sys.platform == 'darwin':  | 
 | 331 | +            # Safari requires real file:-URLs  | 
 | 332 | +            return 'file://' + dochome  | 
 | 333 | +        return dochome  | 
 | 334 | +    else:  | 
 | 335 | +        return "https://docs.python.org/%d.%d/" % sys.version_info[:2]  | 
 | 336 | + | 
 | 337 | + | 
292 | 338 | if __name__ == '__main__':  | 
293 | 339 |     from unittest import main  | 
294 | 340 |     main('idlelib.idle_test.test_help', verbosity=2, exit=False)  | 
 | 
0 commit comments