Skip to content

Commit

Permalink
BUG: Handle import of distutils for python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo authored and kernc committed Jun 22, 2024
1 parent 9b64f7f commit f7f053e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions pdoc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,12 @@ def main(_args=None):
pass # pdoc was not invoked while in a virtual environment
else:
from glob import glob
from distutils.sysconfig import get_python_lib
libdir = get_python_lib(prefix=venv_dir)
if sys.version_info >= (3, 11):
from sysconfig import get_path
libdir = get_path("platlib")
else:
from distutils.sysconfig import get_python_lib
libdir = get_python_lib(prefix=venv_dir)
sys.path.append(libdir)
# Resolve egg-links from `setup.py develop` or `pip install -e`
# XXX: Welcome a more canonical approach
Expand Down
11 changes: 8 additions & 3 deletions pdoc/html_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import inspect
import os
import re
import sys
import subprocess
import textwrap
import traceback
Expand Down Expand Up @@ -624,9 +625,13 @@ def _project_relative_path(absolute_path):
Assumes the project's path is either the current working directory or
Python library installation.
"""
from distutils.sysconfig import get_python_lib
for prefix_path in (_git_project_root() or os.getcwd(),
get_python_lib()):
if sys.version_info >= (3, 11):
from sysconfig import get_path
libdir = get_path("platlib")
else:
from distutils.sysconfig import get_python_lib
libdir = get_python_lib()
for prefix_path in (_git_project_root() or os.getcwd(), libdir):
common_path = os.path.commonpath([prefix_path, absolute_path])
if os.path.samefile(common_path, prefix_path):
# absolute_path is a descendant of prefix_path
Expand Down

0 comments on commit f7f053e

Please sign in to comment.