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

msvc9_query_vcvarsall returns unicode strings on Python 2.7 64-bit and regular strings on 32-bit #992

Closed
cztomczak opened this issue Mar 9, 2017 · 7 comments
Labels

Comments

@cztomczak
Copy link

msvc9_query_vcvarsall returns environment dict with keys "lib", "libpath", "include" and "PATH". On Python 2.7 32-bit values of this dict are regular strings, however on Python 2.7 64-bit this dict contains unicode strings. So when I later use this dict to update os.environ it throws an error:

TypeError: environment can only contain string

Not sure if this is a bug or not, if not you can close it. It's not a big deal for me, I already have it fixed in my code.

@JGoutin
Copy link
Contributor

JGoutin commented Apr 8, 2017

This function monkey patch distutils. I think it return, the unpatched function result in one case and in the patched function result in the other case.

@jaraco
Copy link
Member

jaraco commented Apr 8, 2017

It does seem like a bug. If Python 2.7 os.environ doesn't accept Unicode and msvc9_query_vcvarsall returns only strings in distutils, then the monkeypatch should probably also supply that interface for maximum compatibility.

@jaraco jaraco closed this as completed in b50fdf4 Apr 8, 2017
@jaraco
Copy link
Member

jaraco commented Apr 8, 2017

I've pushed a fix for this issue. @cztomczak, can you copy the latest msvc.py module from master and confirm it fixes the issue in your environment?

@jaraco
Copy link
Member

jaraco commented Apr 8, 2017

Oh, and you'll need py27compat.py as well.

@cztomczak
Copy link
Author

I've added comments to your commit, there seems to be a typo.

jaraco added a commit that referenced this issue Apr 8, 2017
@cztomczak
Copy link
Author

I am sorry, but this issue seems to be invalid and your commits should be reversed. I retested and msvc9_query_vcvarsall() returns unicode on both Python 2.7 32-bit and 64-bit. Previously I have been testing multiple Python flavors and must got confused somewhere on the way. The issue in my code with updating os.environ is still valid, as you can't update it with unicode strings on Python 2.7, however this is not an issue with setuptools. I have checked distutils query_vcvarsall() in distutils/msvc9compiler.py and this function calls str.decode("mbcs"), so it returns unicode strings. So looks like setuptools should be returning unicode strings as well. Again, sorry for causing the trouble.

@cztomczak
Copy link
Author

However there is one bug in setuptools that I've noticed - but that's a separate issue. EnvironmentInfo().return_env() replaces unicode characters with its ascii equivalents. I've added "C:\Tęstą" to my PATH env variable and setuptools returned it as "C:\Testa" - which is an invalid directory. It's not an issue for me, but looks like a bug.

jaraco added a commit that referenced this issue Apr 16, 2017
jaraco added a commit that referenced this issue Apr 16, 2017
@jaraco jaraco added the invalid label Apr 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants