From 82b894dc07b25d5dee783ad7930e85d11738f147 Mon Sep 17 00:00:00 2001 From: John Kleint Date: Tue, 21 Aug 2012 14:35:45 -0400 Subject: [PATCH] Fix assert error when virtual path shares a common prefix with real path. If (real) Python is installed at (say) `/opt/python2.7.3` and you have a virtualenv at `/opt/python`, `change_prefix()` will try to split off `/opt/python` from a path like `/opt/python2.7.3/lib/python2.7/distutils`, leaving `2.7.3/lib/python2.7/distutils`, which is not valid and fails the assert. This patch sorts the list of prefixes by length, so the longer path is tried before its prefix. --- virtualenv.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/virtualenv.py b/virtualenv.py index 7167b439f..d8db8b963 100755 --- a/virtualenv.py +++ b/virtualenv.py @@ -1134,6 +1134,8 @@ def change_prefix(filename, dst_prefix): prefixes.append(sys.base_prefix) prefixes = list(map(os.path.expanduser, prefixes)) prefixes = list(map(os.path.abspath, prefixes)) + # Check longer prefixes first so we don't split in the middle of a filename + prefixes = sorted(prefixes, key=len, reverse=True) filename = os.path.abspath(filename) for src_prefix in prefixes: if filename.startswith(src_prefix):