mirror of
https://github.com/python/cpython.git
synced 2025-11-24 04:17:38 +00:00
[3.14] gh-95844: Move help_url code to a help module function (GH-129971) (#138484)
gh-95844: Move help_url code to a help module function (GH-129971)
---------
(cherry picked from commit 3b4cd88563)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
parent
2f14d23013
commit
cd8fc3aad3
2 changed files with 48 additions and 38 deletions
|
|
@ -29,6 +29,7 @@ from idlelib import search
|
|||
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 @@ class EditorWindow:
|
|||
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
|
||||
|
|
|
|||
|
|
@ -23,7 +23,12 @@ HelpWindow - Display HelpFrame in a standalone window.
|
|||
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() - Return path to docs on user's system if present,
|
||||
otherwise return link to docs.python.org.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
from html.parser import HTMLParser
|
||||
from os.path import abspath, dirname, isfile, join
|
||||
from platform import python_version
|
||||
|
|
@ -289,6 +294,47 @@ def show_idlehelp(parent):
|
|||
return HelpWindow(parent, filename, 'IDLE Doc (%s)' % python_version())
|
||||
|
||||
|
||||
def _get_dochome():
|
||||
"Return path to local docs if present, otherwise 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/'): # rpm package manager
|
||||
dochome = '/var/www/html/python/index.html'
|
||||
else:
|
||||
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 = ''
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue