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

properly handle unicode characters in home dirs #3664

Merged
merged 1 commit into from
Oct 18, 2018

Conversation

vit-tucek
Copy link
Contributor

Jupyter fails to start when the user has Unicode characters in his homedir. This fixes that. See https://github.com/sagemath/sage-windows/issues/10#issuecomment-392137049 and jupyter/jupyter_core#131

@@ -213,6 +213,8 @@ def init_settings(self, jupyter_app, kernel_manager, contents_manager,

root_dir = contents_manager.root_dir
home = os.path.expanduser('~')
if sys.version_info.major == 2:
home = home.decode(sys.getfilesystemencoding())
Copy link
Member

Choose a reason for hiding this comment

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

I believe we have a py3compat.str_to_unicode(s, encoding=sys.getfilesystemencoding())

Related question, though: does os.path.expanduser(u'~') do the right thing here, deferring to Python's on path-encoding logic?

@vit-tucek
Copy link
Contributor Author

Python's path-encoding logic is broken. At least within Sage-on-Windows cygwin environment.

  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/notebook/notebookapp.py", line 214, in init_settings
    home = os.path.expanduser(u'~')
  File "/opt/sagemath-8.2/local/lib/python2.7/posixpath.py", line 293, in expanduser
    return (userhome + path[i:]) or '/'
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)

Changing the line

home = os.path.expanduser('~')

to

home = py3compat.str_to_unicode(os.path.expanduser('~'), encoding=sys.getfilesystemencoding())

works. Do you want me to this change?

@minrk
Copy link
Member

minrk commented Jun 13, 2018

Do you want me to this change?

Yes, that sounds great!

@vit-tucek vit-tucek force-pushed the unicode_home_dirs branch from 7fe954f to 0c7de19 Compare June 13, 2018 15:39
@vit-tucek
Copy link
Contributor Author

Done.

@minrk minrk merged commit 4f9a6cb into jupyter:master Oct 18, 2018
@vit-tucek vit-tucek deleted the unicode_home_dirs branch December 10, 2018 10:17
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants