Skip to content

Commit f7f053e

Browse files
ERosendokernc
authored andcommitted
BUG: Handle import of distutils for python 3.12
1 parent 9b64f7f commit f7f053e

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Diff for: pdoc/cli.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,12 @@ def main(_args=None):
505505
pass # pdoc was not invoked while in a virtual environment
506506
else:
507507
from glob import glob
508-
from distutils.sysconfig import get_python_lib
509-
libdir = get_python_lib(prefix=venv_dir)
508+
if sys.version_info >= (3, 11):
509+
from sysconfig import get_path
510+
libdir = get_path("platlib")
511+
else:
512+
from distutils.sysconfig import get_python_lib
513+
libdir = get_python_lib(prefix=venv_dir)
510514
sys.path.append(libdir)
511515
# Resolve egg-links from `setup.py develop` or `pip install -e`
512516
# XXX: Welcome a more canonical approach

Diff for: pdoc/html_helpers.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import inspect
55
import os
66
import re
7+
import sys
78
import subprocess
89
import textwrap
910
import traceback
@@ -624,9 +625,13 @@ def _project_relative_path(absolute_path):
624625
Assumes the project's path is either the current working directory or
625626
Python library installation.
626627
"""
627-
from distutils.sysconfig import get_python_lib
628-
for prefix_path in (_git_project_root() or os.getcwd(),
629-
get_python_lib()):
628+
if sys.version_info >= (3, 11):
629+
from sysconfig import get_path
630+
libdir = get_path("platlib")
631+
else:
632+
from distutils.sysconfig import get_python_lib
633+
libdir = get_python_lib()
634+
for prefix_path in (_git_project_root() or os.getcwd(), libdir):
630635
common_path = os.path.commonpath([prefix_path, absolute_path])
631636
if os.path.samefile(common_path, prefix_path):
632637
# absolute_path is a descendant of prefix_path

0 commit comments

Comments
 (0)