Skip to content
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

Closed
eryksun opened this issue May 22, 2016 · 13 comments
Closed

PYTHONCASEOK is ignored on Windows #71270

eryksun opened this issue May 22, 2016 · 13 comments
Assignees
Labels
easy OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@eryksun
Copy link
Contributor

eryksun commented May 22, 2016

BPO 27083
Nosy @brettcannon, @rhettinger, @pfmoore, @tjguk, @brianherman, @vadmium, @zware, @serhiy-storchaka, @eryksun, @zooba

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:

assignee = 'https://github.com/brettcannon'
closed_at = <Date 2016-07-16.18:20:12.418>
created_at = <Date 2016-05-22.06:45:31.981>
labels = ['easy', 'type-bug', 'library', 'OS-windows']
title = 'PYTHONCASEOK is ignored on Windows'
updated_at = <Date 2016-07-16.18:20:12.417>
user = 'https://github.com/eryksun'

bugs.python.org fields:

activity = <Date 2016-07-16.18:20:12.417>
actor = 'brett.cannon'
assignee = 'brett.cannon'
closed = True
closed_date = <Date 2016-07-16.18:20:12.418>
closer = 'brett.cannon'
components = ['Library (Lib)', 'Windows']
creation = <Date 2016-05-22.06:45:31.981>
creator = 'eryksun'
dependencies = []
files = []
hgrepos = []
issue_num = 27083
keywords = ['easy']
message_count = 13.0
messages = ['266057', '266302', '270227', '270499', '270500', '270506', '270507', '270508', '270509', '270537', '270544', '270576', '270578']
nosy_count = 11.0
nosy_names = ['brett.cannon', 'rhettinger', 'paul.moore', 'tim.golden', 'Brian.Herman', 'python-dev', 'martin.panter', 'zach.ware', 'serhiy.storchaka', 'eryksun', 'steve.dower']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue27083'
versions = ['Python 3.5', 'Python 3.6']

@eryksun
Copy link
Contributor Author

eryksun commented May 22, 2016

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".

@eryksun eryksun added stdlib Python modules in the Lib dir OS-windows easy type-bug An unexpected behavior, bug, or error labels May 22, 2016
@brettcannon brettcannon self-assigned this May 24, 2016
@serhiy-storchaka
Copy link
Member

Did you forgot to upload a patch?

@brianherman
Copy link
Mannequin

brianherman mannequin commented Jul 12, 2016

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

@python-dev
Copy link
Mannequin

python-dev mannequin commented Jul 15, 2016

New changeset bedcb9ec3f26 by Brett Cannon in branch '3.5':
Issue bpo-27083: Respect the PYTHONCASEOK environment variable under
https://hg.python.org/cpython/rev/bedcb9ec3f26

New changeset 777da58794ca by Brett Cannon in branch 'default':
Merge for bpo-27083
https://hg.python.org/cpython/rev/777da58794ca

@brettcannon
Copy link
Member

I fixed this by simply checking for both b'PYTHONCASEOK' and 'PYTHONCASEOK'. Thanks for the bug report, Eryk!

@serhiy-storchaka
Copy link
Member

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.

@brettcannon
Copy link
Member

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).

@serhiy-storchaka
Copy link
Member

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.

@brettcannon
Copy link
Member

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?

@serhiy-storchaka
Copy link
Member

Yes, I think it will work.

@vadmium
Copy link
Member

vadmium commented Jul 16, 2016

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
======================================================================
FAIL: test_insensitive (test.test_importlib.source.test_case_sensitivity.Frozen_CaseSensitivityTestPEP302)
----------------------------------------------------------------------

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)

@vadmium vadmium reopened this Jul 16, 2016
@python-dev
Copy link
Mannequin

python-dev mannequin commented Jul 16, 2016

New changeset 6b46c1510bfa by Brett Cannon in branch '3.5':
Fix regressions introduced by fixes for issue bpo-27083.
https://hg.python.org/cpython/rev/6b46c1510bfa

New changeset f4c91b883772 by Brett Cannon in branch 'default':
Merge for bpo-27083
https://hg.python.org/cpython/rev/f4c91b883772

@brettcannon
Copy link
Member

Buildbots are green again and I addressed the key type issue. Thanks for letting me know about the failure, Martin.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants