Skip to content

Commit 6879a78

Browse files
committed
make get_friendly_path() more robust on Windows [GH-16]
1 parent a8d1b70 commit 6879a78

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

compdb/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ def stdout_unicode_writer():
7070

7171
def get_friendly_path(path):
7272
full_path = os.path.normpath(path)
73-
rel_path = os.path.relpath(full_path)
73+
try:
74+
rel_path = os.path.relpath(full_path)
75+
except ValueError:
76+
# on Windows, we can get a ValueError
77+
# if the current directory is on another drive:
78+
# > ValueError: path is on drive D:, start on drive C:
79+
# > -- https://github.com/Sarcasm/compdb/issues/16
80+
return full_path
7481
if rel_path.startswith(os.path.join(os.pardir, os.pardir)):
7582
friendly_path = full_path
7683
else:

0 commit comments

Comments
 (0)