New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PYTHONCASEOK is ignored on Windows #71270
Comments
importlib ignores the PYTHONCASEOK environment variable on Windows. _relax_case checks for b'PYTHONCASEOK' in os.environ, which is never true because os.environ is Unicode. On Windows, _make_relax_case should return a function that instead checks for 'PYTHONCASEOK'. The following test demonstrates that case-insensitive imports otherwise appear to work correctly in 3.5: >>> import sys, importlib, glob
>>> glob.glob('*.py')
['Test.py']
>>> importlib._bootstrap_external._relax_case()
False
>>> import test
>>> test.__file__
'C:\\Program Files\\Python35\\lib\\test\\__init__.py' patched: >>> src = "_relax_case = lambda: 'PYTHONCASEOK' in _os.environ"
>>> exec(src, vars(importlib._bootstrap_external))
>>> importlib._bootstrap_external._relax_case()
True
>>> del sys.modules['test']
>>> import test
this is a test
>>> test.__file__
'C:\\Temp\\test.py' It would be better if __file__ were the actual filename "Test.py" instead of "test.py". |
Did you forgot to upload a patch? |
In python 3.6 from hg it has been fixed. >>> glob.glob('*.py')
['setup.py', 'test.py']
>>> import test
>>> test.__file__
'C:\\Users\\brian\\Desktop\\cpython\\test.py'
>>> |
New changeset bedcb9ec3f26 by Brett Cannon in branch '3.5': New changeset 777da58794ca by Brett Cannon in branch 'default': |
I fixed this by simply checking for both b'PYTHONCASEOK' and 'PYTHONCASEOK'. Thanks for the bug report, Eryk! |
Comparing bytes with str can emit a warning or raise an exception. Checking for b'PYTHONCASEOK' in os.environ looks as a bug to me. |
There's no direct comparison to trigger a warning; it's just seeing if a key in a dict exists. And b'PYTHONCASEOK' is not a bug as that's required for OS X (remember this is technically posix.environ, not os.environ). |
Seeing if a key in a dict exists involves the key comparison if there is a key on the same position in the hash table. |
I think the best we can do is be platform-specific in what is checked for in the environ dict (e.g. b'PYTHONCASEOK' on darwin, 'PYTHONCASEOK' on win, and I don't know about cygwin), but otherwise one would have to iterate through the keys of the dict and do a type check before doing the comparison to fully avoid any potential warning being triggered. Does the platform-specific decision of what to look for work for you, Serhiy? |
Yes, I think it will work. |
This appears to have broken the tests on Windows: http://buildbot.python.org/all/builders/x86%20Windows7%203.5/builds/1030/steps/test/logs/stdio Traceback (most recent call last):
File "D:\cygwin\home\db3l\buildarea\3.5.bolen-windows7\build\lib\test\test_importlib\source\test_case_sensitivity.py", line 65, in test_insensitive
self.assertIsNotNone(insensitive)
AssertionError: unexpectedly None (Plus three more failures) |
New changeset 6b46c1510bfa by Brett Cannon in branch '3.5': New changeset f4c91b883772 by Brett Cannon in branch 'default': |
Buildbots are green again and I addressed the key type issue. Thanks for letting me know about the failure, Martin. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: