Skip to content

Commit

Permalink
Fix assert error when virtual path shares a common prefix with real p…
Browse files Browse the repository at this point in the history
…ath.

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.
  • Loading branch information
John Kleint committed Oct 19, 2012
1 parent 4cd1a4d commit 82b894d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 82b894d

Please sign in to comment.