change_prefix should ignore case on case-insensitive file systems #815

Closed
mjpieters opened this Issue Nov 3, 2015 · 2 comments

Projects

None yet

3 participants

@mjpieters

On Windows, people can end up with a PYTHONPATH that leads to:

Traceback (most recent call last):
  File "C:\Python27\Scripts\virtualenv-script.py", line 9, in <module>
    load_entry_point('virtualenv==1.5.2', 'console_scripts', 'virtualenv')()
  File "C:\Python27\lib\site-packages\virtualenv.py", line 558, in main
    prompt=options.prompt)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 647, in create_environment
    site_packages=site_packages, clear=clear))
  File "C:\Python27\lib\site-packages\virtualenv.py", line 771, in install_python
    copy_required_modules(home_dir)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 725, in copy_required_modules
    dst_filename = change_prefix(filename, dst_prefix)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 710, in change_prefix
    (filename, prefixes)
AssertionError: Filename c:\Python27\Lib\os.py does not start with any of these prefixes: ['C:\\Python27']

where PYTHONPATH is set to c:\Python27;c:\Python27\Lib (lowercase c). The function should really use os.path.normcase() on the prefixes and the filename.

@Ivoz
Member
Ivoz commented Jan 29, 2016

@mjpieters unfortunately normcase will lowercase everything, which is actually not what you want. Python 2 will actually manage to error out on an incorrect filepath case, somehow.

@Ivoz Ivoz added a commit that referenced this issue Jan 29, 2016
@Ivoz Ivoz Revert ac4ea65; only correct drive letter case.
Fixes #856, #815
e263dd6
@Ivoz Ivoz closed this Jan 29, 2016
@tlynn
tlynn commented Feb 2, 2016

This fix looks incomplete, i.e. the problem looks likely to still be present when the case difference happens after the drive letter. normcase is the right thing to use for the comparison, but the normcased version of the filename should then be discarded.

How Windows actually compares paths (allegedly): http://stackoverflow.com/a/8900148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment