Skip to content

Commit b5017de

Browse files
miss-islingtonStanFromIrelandterryjreedy
authored
[3.13] gh-95844: Move help_url code to a help module function (GH-129971) (#138485)
gh-95844: Move help_url code to a help module function (GH-129971) --------- (cherry picked from commit 3b4cd88) Co-authored-by: Stan Ulbrych <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent 0dcff3d commit b5017de

File tree

2 files changed

+48
-38
lines changed

2 files changed

+48
-38
lines changed

Lib/idlelib/editor.py

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from idlelib.tree import wheel_event
3030
from idlelib.util import py_extensions
3131
from idlelib import window
32+
from idlelib.help import _get_dochome
3233

3334
# The default tab setting for a Text widget, in average-width characters.
3435
TK_TABWIDTH_DEFAULT = 8
@@ -76,44 +77,7 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
7677
from idlelib.runscript import ScriptBinding
7778

7879
if EditorWindow.help_url is None:
79-
dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html')
80-
if sys.platform.count('linux'):
81-
# look for html docs in a couple of standard places
82-
pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3]
83-
if os.path.isdir('/var/www/html/python/'): # "python2" rpm
84-
dochome = '/var/www/html/python/index.html'
85-
else:
86-
basepath = '/usr/share/doc/' # standard location
87-
dochome = os.path.join(basepath, pyver,
88-
'Doc', 'index.html')
89-
elif sys.platform[:3] == 'win':
90-
import winreg # Windows only, block only executed once.
91-
docfile = ''
92-
KEY = (rf"Software\Python\PythonCore\{sys.winver}"
93-
r"\Help\Main Python Documentation")
94-
try:
95-
docfile = winreg.QueryValue(winreg.HKEY_CURRENT_USER, KEY)
96-
except FileNotFoundError:
97-
try:
98-
docfile = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
99-
KEY)
100-
except FileNotFoundError:
101-
pass
102-
if os.path.isfile(docfile):
103-
dochome = docfile
104-
elif sys.platform == 'darwin':
105-
# documentation may be stored inside a python framework
106-
dochome = os.path.join(sys.base_prefix,
107-
'Resources/English.lproj/Documentation/index.html')
108-
dochome = os.path.normpath(dochome)
109-
if os.path.isfile(dochome):
110-
EditorWindow.help_url = dochome
111-
if sys.platform == 'darwin':
112-
# Safari requires real file:-URLs
113-
EditorWindow.help_url = 'file://' + EditorWindow.help_url
114-
else:
115-
EditorWindow.help_url = ("https://docs.python.org/%d.%d/"
116-
% sys.version_info[:2])
80+
EditorWindow.help_url = _get_dochome()
11781
self.flist = flist
11882
root = root or flist.root
11983
self.root = root

Lib/idlelib/help.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
copy_strip - Copy the text part of idle.html to help.html while rstripping each line.
2424
2525
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.
2629
"""
30+
import os
31+
import sys
2732
from html.parser import HTMLParser
2833
from os.path import abspath, dirname, isfile, join
2934
from platform import python_version
@@ -289,6 +294,47 @@ def show_idlehelp(parent):
289294
return HelpWindow(parent, filename, 'IDLE Doc (%s)' % python_version())
290295

291296

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+
292338
if __name__ == '__main__':
293339
from unittest import main
294340
main('idlelib.idle_test.test_help', verbosity=2, exit=False)

0 commit comments

Comments
 (0)