[Python-checkins] bpo-21016: pydoc and trace use sysconfig (GH-18476)

Miss Islington (bot) webhook-mailer at python.org
Wed Feb 12 07:32:59 EST 2020


https://github.com/python/cpython/commit/ac6f4d2db703c0ff88e496bcb7b7fe55cf2ac458
commit: ac6f4d2db703c0ff88e496bcb7b7fe55cf2ac458
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-02-12T04:32:52-08:00
summary:

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 <jmatejek at suse.com>
(cherry picked from commit 4fac7ed43ebf1771a8fe86fdfe7b9991f3be78cd)

Co-authored-by: Victor Stinner <vstinner at python.org>

files:
A Misc/NEWS.d/next/Library/2020-02-12-10-04-39.bpo-21016.bFXPH7.rst
M Lib/pydoc.py
M Lib/trace.py

diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 9a22e56686f61..dc3377d68f8ca 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -66,6 +66,7 @@ class or function within a module or module in a package.  If the
 import platform
 import re
 import sys
+import sysconfig
 import time
 import tokenize
 import urllib.parse
@@ -392,9 +393,7 @@ def fail(self, object, name=None, *args):
 
     docmodule = docclass = docroutine = docother = docproperty = docdata = fail
 
-    def getdocloc(self, object,
-                  basedir=os.path.join(sys.base_exec_prefix, "lib",
-                                       "python%d.%d" %  sys.version_info[:2])):
+    def getdocloc(self, object, basedir=sysconfig.get_path('stdlib')):
         """Return the location of module docs or None"""
 
         try:
diff --git a/Lib/trace.py b/Lib/trace.py
index 62325d3f238ad..a44735761df42 100755
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -52,6 +52,7 @@
 import linecache
 import os
 import sys
+import sysconfig
 import token
 import tokenize
 import inspect
@@ -676,9 +677,8 @@ def main():
     opts = parser.parse_args()
 
     if opts.ignore_dir:
-        rel_path = 'lib', 'python{0.major}.{0.minor}'.format(sys.version_info)
-        _prefix = os.path.join(sys.base_prefix, *rel_path)
-        _exec_prefix = os.path.join(sys.base_exec_prefix, *rel_path)
+        _prefix = sysconfig.get_path("stdlib")
+        _exec_prefix = sysconfig.get_path("platstdlib")
 
     def parse_ignore_dir(s):
         s = os.path.expanduser(os.path.expandvars(s))
diff --git a/Misc/NEWS.d/next/Library/2020-02-12-10-04-39.bpo-21016.bFXPH7.rst b/Misc/NEWS.d/next/Library/2020-02-12-10-04-39.bpo-21016.bFXPH7.rst
new file mode 100644
index 0000000000000..fb91bb3825555
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-02-12-10-04-39.bpo-21016.bFXPH7.rst
@@ -0,0 +1,4 @@
+The :mod:`pydoc` and :mod:`trace` modules now use the :mod:`sysconfig`
+module to get the path to the Python standard library, to support uncommon
+installation path like ``/usr/lib64/python3.9/`` on Fedora.
+Patch by Jan Matějek.



More information about the Python-checkins mailing list