Skip to content

Commit ca133e5

Browse files
bpo-21016: pydoc and trace use sysconfig (GH-18476)
bpo-21016, bpo-1294959: The pydoc and trace modules now use the sysconfig module to get the path to the Python standard library, to support uncommon installation path like /usr/lib64/python3.9/ on Fedora. Co-Authored-By: Jan Matějek <[email protected]> (cherry picked from commit 4fac7ed) Co-authored-by: Victor Stinner <[email protected]>
1 parent a933f74 commit ca133e5

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Lib/pydoc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class or function within a module or module in a package. If the
6666
import platform
6767
import re
6868
import sys
69+
import sysconfig
6970
import time
7071
import tokenize
7172
import urllib.parse
@@ -398,9 +399,7 @@ def fail(self, object, name=None, *args):
398399

399400
docmodule = docclass = docroutine = docother = docproperty = docdata = fail
400401

401-
def getdocloc(self, object,
402-
basedir=os.path.join(sys.base_exec_prefix, "lib",
403-
"python%d.%d" % sys.version_info[:2])):
402+
def getdocloc(self, object, basedir=sysconfig.get_path('stdlib')):
404403
"""Return the location of module docs or None"""
405404

406405
try:

Lib/trace.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import os
5454
import re
5555
import sys
56+
import sysconfig
5657
import token
5758
import tokenize
5859
import inspect
@@ -671,9 +672,8 @@ def main():
671672
opts = parser.parse_args()
672673

673674
if opts.ignore_dir:
674-
rel_path = 'lib', 'python{0.major}.{0.minor}'.format(sys.version_info)
675-
_prefix = os.path.join(sys.base_prefix, *rel_path)
676-
_exec_prefix = os.path.join(sys.base_exec_prefix, *rel_path)
675+
_prefix = sysconfig.get_path("stdlib")
676+
_exec_prefix = sysconfig.get_path("platstdlib")
677677

678678
def parse_ignore_dir(s):
679679
s = os.path.expanduser(os.path.expandvars(s))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The :mod:`pydoc` and :mod:`trace` modules now use the :mod:`sysconfig`
2+
module to get the path to the Python standard library, to support uncommon
3+
installation path like ``/usr/lib64/python3.9/`` on Fedora.
4+
Patch by Jan Matějek.

0 commit comments

Comments
 (0)