Skip to content

Commit 46d3291

Browse files
committed
ENH: Minor refactor _project_relative_path, aid in debugging
Refs: #456
1 parent 0bcb40f commit 46d3291

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pdoc/html_helpers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,19 @@ def _project_relative_path(absolute_path):
626626
Python library installation.
627627
"""
628628
from sysconfig import get_path
629-
libdir = get_path("platlib")
630-
for prefix_path in (_git_project_root() or os.getcwd(), libdir):
629+
paths = filter(None, (
630+
_git_project_root() or os.getcwd(),
631+
get_path("stdlib"),
632+
get_path("platlib"),
633+
))
634+
for prefix_path in map(os.path.realpath, paths):
631635
common_path = os.path.commonpath([prefix_path, absolute_path])
632636
if os.path.samefile(common_path, prefix_path):
633637
# absolute_path is a descendant of prefix_path
634638
return os.path.relpath(absolute_path, prefix_path)
635639
raise RuntimeError(
636640
f"absolute path {absolute_path!r} is not a descendant of the current working directory "
637-
"or of the system's python library."
641+
f"or of the system's python library {paths}."
638642
)
639643

640644

0 commit comments

Comments
 (0)