Merge pull request #30 from skorokithakis/patch-1

Fix import issue when a shorter base path matches before a shorter one
This commit is contained in:
Salvador E. Tropea 2020-12-09 12:37:34 -03:00 committed by GitHub
commit 5a981bbd81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -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