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

Open configuration file with utf-8 encoding on Windows and Python 2 #2219

Merged
merged 4 commits into from Mar 10, 2015

Conversation

vasily-smirnov
Copy link
Contributor

This change is related to issue 2081 for the case when user home directory contains non-ascii characters and Spyder reads/writes INI file into that directory.
This change does NOT resolve the issue 2081 (there are cases with non-ascii working directory and plus some dependencies out of Spyder codebase).
This change seems failsafe.

Fixes #2081

if osp.isfile(fname):
try:
with codecs.open(fname, encoding='utf-8') as configfile:
self.readfp(configfile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to use readfp instead of read here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read() expects filename and does file open itself, readfp() expects open file handle

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought that was the case. So codecs.open returns the file handle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, exactly

@ccordoba12
Copy link
Member

@vasily-smirnov, thanks a lot your contribution! Let's hope this finishes all the problems we've had with non-ascii accounts on Windows :-)

I just have a minor (clarification) comment before merging

@ccordoba12 ccordoba12 changed the title userconfig.py Open configuration file with utf-8 encoding on Windows and Python 2 Mar 4, 2015
@ccordoba12 ccordoba12 added this to the v2.3.4 milestone Mar 4, 2015
@ccordoba12
Copy link
Member

@vasily-smirnov, I think changing codecs.open to io.open is important before merging.

@vasily-smirnov
Copy link
Contributor Author

done as you suggested, not tested

@ccordoba12
Copy link
Member

I tested it and unfortunately is not working. io requires that all strings written to spyder.ini be unicode, which doesn't make much sense.

Sorry for making you waste your time, but please revert to use codecs instead of io, which is working just fine :-)

@vasily-smirnov
Copy link
Contributor Author

no problem, done, thanks for testing

ccordoba12 added a commit that referenced this pull request Mar 10, 2015
Open configuration file with utf-8 encoding on Windows and Python 2
@ccordoba12 ccordoba12 merged commit 66ee1f8 into spyder-ide:master Mar 10, 2015
@ccordoba12
Copy link
Member

Thanks a lot for your work.

@vasily-smirnov
Copy link
Contributor Author

de nada! I like spyder very much :-)

@ccordoba12
Copy link
Member

Muchas gracias ;-)

ccordoba12 added a commit that referenced this pull request Mar 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spyder crashes on Windows because of non-ascii chars in working directory
2 participants