File tree 1 file changed +9
-2
lines changed 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -581,7 +581,10 @@ def absolutepath(path: Union[Path, str]) -> Path:
581
581
582
582
def commonpath (path1 : Path , path2 : Path ) -> Optional [Path ]:
583
583
"""Return the common part shared with the other path, or None if there is
584
- no common part."""
584
+ no common part.
585
+
586
+ If one path is relative and one is absolute, returns None.
587
+ """
585
588
try :
586
589
return Path (os .path .commonpath ((str (path1 ), str (path2 ))))
587
590
except ValueError :
@@ -592,13 +595,17 @@ def bestrelpath(directory: Path, dest: Path) -> str:
592
595
"""Return a string which is a relative path from directory to dest such
593
596
that directory/bestrelpath == dest.
594
597
598
+ The paths must be either both absolute or both relative.
599
+
595
600
If no such path can be determined, returns dest.
596
601
"""
597
602
if dest == directory :
598
603
return os .curdir
599
604
# Find the longest common directory.
600
605
base = commonpath (directory , dest )
601
- # Can be the case on Windows.
606
+ # Can be the case on Windows for two absolute paths on different drives.
607
+ # Can be the case for two relative paths without common prefix.
608
+ # Can be the case for a relative path and an absolute path.
602
609
if not base :
603
610
return str (dest )
604
611
reldirectory = directory .relative_to (base )
You can’t perform that action at this time.
0 commit comments