Commit c2d8dab8 authored by Christoph Reiter's avatar Christoph Reiter 🐍

scanner: Fix error on Windows in case source files are on different drives

os.path.commonpath() raises ValueError if the paths given to it are on different

Handle that case by giving up and add a test.

Reported here:
parent 7c2781c4
Pipeline #76775 passed with stages
in 5 minutes and 21 seconds
......@@ -505,7 +505,12 @@ def get_source_root_dirs(options, filenames):
if not dirs:
return []
common = os.path.commonpath(dirs)
common = os.path.commonpath(dirs)
except ValueError:
# ValueError: On Windows in case the paths are on different drives
return dirs
# If the only common path is the root directory give up
if os.path.dirname(common) == common:
return dirs
......@@ -25,6 +25,16 @@ class TestScanner(unittest.TestCase):
paths = get_source_root_dirs(options, [])
self.assertEqual(paths, [])
@unittest.skipUnless( == "nt", "Windows only")
def test_get_source_root_dirs_different_drives(self):
options = optparse.Values({"sources_top_dirs": []})
names = [
os.path.join("X:", os.sep, "foo"),
os.path.join("Y:", os.sep, "bar"),
paths = get_source_root_dirs(options, names)
self.assertEqual(paths, list(map(os.path.dirname, names)))
if __name__ == '__main__':
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment