From 70a47a6e8ed8776830c22d6881fd97b4130857c2 Mon Sep 17 00:00:00 2001 From: stan Date: Mon, 10 Feb 2025 18:36:18 +0000 Subject: [PATCH 1/6] Move finding dochome logic to separate function in help.py --- Lib/idlelib/editor.py | 40 ++-------------------------------------- Lib/idlelib/help.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index c76db20c58792d..05feb046483b76 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -29,6 +29,7 @@ from idlelib.tree import wheel_event from idlelib.util import py_extensions from idlelib import window +from idlelib.help import _get_dochome # The default tab setting for a Text widget, in average-width characters. TK_TABWIDTH_DEFAULT = 8 @@ -76,44 +77,7 @@ def __init__(self, flist=None, filename=None, key=None, root=None): from idlelib.runscript import ScriptBinding if EditorWindow.help_url is None: - dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html') - if sys.platform.count('linux'): - # look for html docs in a couple of standard places - pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3] - if os.path.isdir('/var/www/html/python/'): # "python2" rpm - dochome = '/var/www/html/python/index.html' - else: - basepath = '/usr/share/doc/' # standard location - dochome = os.path.join(basepath, pyver, - 'Doc', 'index.html') - elif sys.platform[:3] == 'win': - import winreg # Windows only, block only executed once. - docfile = '' - KEY = (rf"Software\Python\PythonCore\{sys.winver}" - r"\Help\Main Python Documentation") - try: - docfile = winreg.QueryValue(winreg.HKEY_CURRENT_USER, KEY) - except FileNotFoundError: - try: - docfile = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, - KEY) - except FileNotFoundError: - pass - if os.path.isfile(docfile): - dochome = docfile - elif sys.platform == 'darwin': - # documentation may be stored inside a python framework - dochome = os.path.join(sys.base_prefix, - 'Resources/English.lproj/Documentation/index.html') - dochome = os.path.normpath(dochome) - if os.path.isfile(dochome): - EditorWindow.help_url = dochome - if sys.platform == 'darwin': - # Safari requires real file:-URLs - EditorWindow.help_url = 'file://' + EditorWindow.help_url - else: - EditorWindow.help_url = ("https://docs.python.org/%d.%d/" - % sys.version_info[:2]) + EditorWindow.help_url = _get_dochome() self.flist = flist root = root or flist.root self.root = root diff --git a/Lib/idlelib/help.py b/Lib/idlelib/help.py index 063a749df54bc0..f3f53a82e053da 100644 --- a/Lib/idlelib/help.py +++ b/Lib/idlelib/help.py @@ -24,6 +24,8 @@ show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog. """ +import os +import sys from html.parser import HTMLParser from os.path import abspath, dirname, isfile, join from platform import python_version @@ -35,6 +37,9 @@ from idlelib.config import idleConf from idlelib.colorizer import color_config +from idlelib.editor import EditorWindow + + ## About IDLE ## @@ -289,6 +294,44 @@ def show_idlehelp(parent): return HelpWindow(parent, filename, 'IDLE Doc (%s)' % python_version()) +def _get_dochome(): + dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html') + if sys.platform.count('linux'): + # look for html docs in a couple of standard places + pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3] + if os.path.isdir('/var/www/html/python/'): # "python2" rpm + dochome = '/var/www/html/python/index.html' + else: + basepath = '/usr/share/doc/' # standard location + dochome = os.path.join(basepath, pyver, + 'Doc', 'index.html') + elif sys.platform[:3] == 'win': + import winreg # Windows only, block only executed once. + docfile = '' + KEY = (rf"Software\Python\PythonCore\{sys.winver}" + r"\Help\Main Python Documentation") + try: + docfile = winreg.QueryValue(winreg.HKEY_CURRENT_USER, KEY) + except FileNotFoundError: + try: + docfile = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, KEY) + except FileNotFoundError: + pass + if os.path.isfile(docfile): + dochome = docfile + elif sys.platform == 'darwin': + # documentation may be stored inside a python framework + dochome = os.path.join(sys.base_prefix, + 'Resources/English.lproj/Documentation/index.html') + dochome = os.path.normpath(dochome) + if os.path.isfile(dochome): + if sys.platform == 'darwin': + # Safari requires real file:-URLs + return 'file://' + dochome + return dochome + else: + return "https://docs.python.org/%d.%d/" % sys.version_info[:2] + if __name__ == '__main__': from unittest import main main('idlelib.idle_test.test_help', verbosity=2, exit=False) From 51f729c56630689df47facb2c6c91179ea91c21f Mon Sep 17 00:00:00 2001 From: stan Date: Mon, 10 Feb 2025 19:27:22 +0000 Subject: [PATCH 2/6] Fix import --- Lib/idlelib/help.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Lib/idlelib/help.py b/Lib/idlelib/help.py index f3f53a82e053da..3805822bbb663a 100644 --- a/Lib/idlelib/help.py +++ b/Lib/idlelib/help.py @@ -37,9 +37,6 @@ from idlelib.config import idleConf from idlelib.colorizer import color_config -from idlelib.editor import EditorWindow - - ## About IDLE ## From 9a57bfa1526bdc6f4e154b0e1525392202d2694f Mon Sep 17 00:00:00 2001 From: stan Date: Tue, 11 Feb 2025 11:46:19 +0000 Subject: [PATCH 3/6] Add docstrings and comments --- Lib/idlelib/help.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Lib/idlelib/help.py b/Lib/idlelib/help.py index 3805822bbb663a..f59a5cd43fc358 100644 --- a/Lib/idlelib/help.py +++ b/Lib/idlelib/help.py @@ -23,6 +23,8 @@ copy_strip - Copy the text part of idle.html to help.html while rstripping each line. show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog. + +_get_dochome() - Returns path to docs on users system if none found returns link to docs.python.org """ import os import sys @@ -292,16 +294,20 @@ def show_idlehelp(parent): def _get_dochome(): + """Returns path to local docs + + If none found returns link to docs.python.org. + """ dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html') if sys.platform.count('linux'): # look for html docs in a couple of standard places pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3] - if os.path.isdir('/var/www/html/python/'): # "python2" rpm + if os.path.isdir('/var/www/html/python/'): # rpm package manager dochome = '/var/www/html/python/index.html' else: - basepath = '/usr/share/doc/' # standard location - dochome = os.path.join(basepath, pyver, - 'Doc', 'index.html') + basepath = '/usr/share/doc/' # dnf/apt package managers + dochome = os.path.join(basepath, pyver, 'Doc', 'index.html') + elif sys.platform[:3] == 'win': import winreg # Windows only, block only executed once. docfile = '' From ce4268d4848470407cfc54f9d834c86d92deb915 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 3 Sep 2025 17:00:23 -0400 Subject: [PATCH 4/6] Update Lib/idlelib/help.py --- Lib/idlelib/help.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/idlelib/help.py b/Lib/idlelib/help.py index f59a5cd43fc358..282b5eb53d14be 100644 --- a/Lib/idlelib/help.py +++ b/Lib/idlelib/help.py @@ -24,7 +24,8 @@ show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog. -_get_dochome() - Returns path to docs on users system if none found returns link to docs.python.org +_get_dochome() - Return path to docs on user's system if present, +otherwise return link to docs.python.org. """ import os import sys From 43295cdda95afd3beb93950814d2b47fd0bad220 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 3 Sep 2025 17:00:31 -0400 Subject: [PATCH 5/6] Update Lib/idlelib/help.py --- Lib/idlelib/help.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lib/idlelib/help.py b/Lib/idlelib/help.py index 282b5eb53d14be..875b505d49a499 100644 --- a/Lib/idlelib/help.py +++ b/Lib/idlelib/help.py @@ -295,10 +295,8 @@ def show_idlehelp(parent): def _get_dochome(): - """Returns path to local docs + "Return path to local docs if present, otherwise link to docs.python.org." - If none found returns link to docs.python.org. - """ dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html') if sys.platform.count('linux'): # look for html docs in a couple of standard places From f43cf081dc96c3db108184466c83520f8215a917 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 3 Sep 2025 17:00:37 -0400 Subject: [PATCH 6/6] Update Lib/idlelib/help.py --- Lib/idlelib/help.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/idlelib/help.py b/Lib/idlelib/help.py index 875b505d49a499..48e7eca280ebf8 100644 --- a/Lib/idlelib/help.py +++ b/Lib/idlelib/help.py @@ -334,6 +334,7 @@ def _get_dochome(): else: return "https://docs.python.org/%d.%d/" % sys.version_info[:2] + if __name__ == '__main__': from unittest import main main('idlelib.idle_test.test_help', verbosity=2, exit=False)