From aae76c638881e7dda8a83430ab08af1689c5ccdb Mon Sep 17 00:00:00 2001 From: Stavros Korokithakis Date: Wed, 9 Dec 2020 16:49:18 +0200 Subject: [PATCH] Fix import issue when a shorter base path matches before a shorter one --- kibot/mcpyrate/coreutils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kibot/mcpyrate/coreutils.py b/kibot/mcpyrate/coreutils.py index 1696077d..23495113 100644 --- a/kibot/mcpyrate/coreutils.py +++ b/kibot/mcpyrate/coreutils.py @@ -56,7 +56,9 @@ def match_syspath(filename): If `filename` is not under any directory in `sys.path`, raises `ValueError`. """ absolute_filename = str(pathlib.Path(filename).expanduser().resolve()) - for root_path in sys.path: + # We sort the paths in reverse order of length so a longer path matches + # before a shorter one. + for root_path in sorted(sys.path, key=len, reverse=True): root_path = pathlib.Path(root_path).expanduser().resolve() if absolute_filename.startswith(str(root_path)): return root_path