[gobject-introspection] gicsanner/message.py: Windows: Fix running on different drives
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] gicsanner/message.py: Windows: Fix running on different drives
- Date: Sat, 26 Sep 2020 10:21:50 +0000 (UTC)
commit 0de9608f6f23fc837122fdf52528774ae47acc25
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Fri Sep 18 15:06:36 2020 +0800
gicsanner/message.py: Windows: Fix running on different drives
os.path.relpath() will throw a ValueError when the two paths that
are fed to it are on different drives, at least when running under
cmd.exe consoles.
Fix this by falling back to the full path when this ValueError is
thrown.
giscanner/message.py | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/giscanner/message.py b/giscanner/message.py
index 9057c23c1..24f1b7dfe 100644
--- a/giscanner/message.py
+++ b/giscanner/message.py
@@ -75,8 +75,14 @@ class Position(object):
self.column or -1)
def format(self, cwd):
- filename = os.path.relpath(os.path.realpath(self.filename),
- os.path.realpath(cwd))
+ # Windows: We may be using different drives self.filename and cwd,
+ # which leads to a ValuError when using os.path.relpath().
+ # In that case, just use the entire path of self.filename
+ try:
+ filename = os.path.relpath(os.path.realpath(self.filename),
+ os.path.realpath(cwd))
+ except ValueError:
+ filename = os.path.realpath(self.filename)
if self.column is not None:
return '%s:%d:%d' % (filename, self.line, self.column)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]