Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Allow user to set their default "home" directory at install time #10

Closed
embray opened this issue Dec 9, 2017 · 21 comments
Closed

Allow user to set their default "home" directory at install time #10

embray opened this issue Dec 9, 2017 · 21 comments

Comments

@embray
Copy link
Contributor

embray commented Dec 9, 2017

Windows more or less has a home directory in the form of C:\Users\<username> (at least this is the default, although Windows has a variable to refer to this directory's actual location for a given user that we use through Cygwin to set their home directory). Absent any other input this is generally the best choice, but it might not always be. As this question reminds us, some users may already have a preferred location, either under their home directory or somewhere else entirely, where they prefer to keep Sage-related files by default.

It would be easy to change this for them at installation time by giving them the opportunity to set this path from something other than the default. Later we might also add a graphical configuration panel to change this (since the only alternative is editing some text config files). But I in the short term an install-time option should serve most cases.

Workaround

Most users can work around around this--especially if they are the only users of their machines (the most common case, really)--by editing the /etc/fstab file in the Sage+Cygwin install. The Windows path to this file is given by running the following in the Sage Shell:

$ cygpath -w -a /etc/fstab
C:\Program Files\SageMath 8.2\runtime\etc\fstab

it should be the same as above for the default install location (and also dependent on the Sage version).

If you're familiar with Linux, this is similar to the fstab file there, with slightly different Cygwin-specific syntax and options.

At the bottom of this file is a line:

C:\Users /home ntfs binary,posix=1,acl 0 0

which sets up the mappings for all users on the system. If you want
to add a specific mapping for your personal home directory, it should
work if you add under this line a similar line like:

C:\Users\<Your Windows Username>\<Your preferred Sage home> /home/<Your Windows username> ntfs binary,posix=1,acl 0 0

e.g. on my machine this would be something like:

C:\Users\Erik\Dropbox /home/Erik ntfs binary,posix=1,acl 0 0

Be careful if your username contains spaces. In this case they have to be escaped like \040. I'm also not sure how this handles non-ASCII characters. I believe it can, but they might needs to be escaped as well.

@embray
Copy link
Contributor Author

embray commented Dec 11, 2017

One slight challenge to this is that the installer itself is not generally user-specific. It installs Sage for the whole system. That said, most Windows systems are going to be single-user in practice, so maybe we could still include this option at install time and have it only apply to the user running the installer. Not totally sure how I feel about that though.

@danielvolinski
Copy link

Since Windows already has the possibility of defining user environment variables, I suggest defining a specific Sagemath environment variable like SAGE_HOME to be set by the user which will indicate Sagemath where to start the folder system.

@Akababa
Copy link

Akababa commented Dec 14, 2017

Which config file can I edit currently to change SAGE_HOME? (env vars don't work )

@embray
Copy link
Contributor Author

embray commented Dec 15, 2017

It's not as simple as setting an environment variable, unfortunately, though that may not be a bad place to start.

@Akababa
Copy link

Akababa commented Dec 15, 2017

Yeah I already tried that :( I mean, which config file would I have to edit to change the home directory.

@embray
Copy link
Contributor Author

embray commented Dec 15, 2017

@Akababa There is no SAGE_HOME. It was just a suggestion by @danielvolinski. I am working on a solution.

@Akababa
Copy link

Akababa commented Dec 15, 2017

I was referring to this from the comment in the link in OP:

Now, if you want Sage to always start in a different directory this can be done too, but is a bit tricky and requires editing some startup files. I can get back to you later on that if you think it's worth bothering.

Btw thanks for your hard work!

@embray
Copy link
Contributor Author

embray commented Dec 15, 2017

Yes, but have some patience. Like I said, it's a bit tricky to get right and I need to make sure I know the right answer before I tell you.

@vit-tucek
Copy link

Jupyter's migrate script seems to have an encoding issue when the username contains diacritical marks.

@embray
Copy link
Contributor Author

embray commented May 9, 2018

@vit-tucek Could you provide more details? I don't know what "Jupyter's migrate script" is. Anyways, that would not be directly related to this issue. Perhaps you could open a new one (or an issue with Jupyter).

@embray
Copy link
Contributor Author

embray commented May 14, 2018

For those interested I've updated the description of this issue with a possible workaround that should work for individual users. It's not ideal but it's better than nothing.

@vit-tucek
Copy link

vit-tucek commented May 20, 2018

@embray Sorry, I was busy. Details are in the description of my pull request.

@embray
Copy link
Contributor Author

embray commented May 21, 2018

@vit-tucek It looks like you closed that PR already? But indeed, I don't think that's the correct fix. However, you can always update an existing pull request by doing a force push (git push -f) to the branch associated with the PR.

That said, you might consider just opening an issue explaining how to reproduce the problem and someone on the Jupyter team can probably fix it.

@vit-tucek
Copy link

@embray Is git push -f acceptable practice in cases like these? I've created another pull request where I check for sys.version_info.major == 2 and all tests pass. I've skimmed through Jupyter's dev guidelines and I'm not sure if I need to open a PR for this. I think the description in my pull request contains every information needed to reproduce this issue and the patch is pretty much one-liner.

By the way, thank you for writing up the workaround for this PR, because this is my first time using cygwin on W10 and without cygpath I would've been lost.

@embray
Copy link
Contributor Author

embray commented May 22, 2018

Is git push -f acceptable practice in cases like these?

Yes, you are only updating a branch on your personal fork of the repository. GitHub can handle updating the PR even when the contents of the branch are completely replaced. This is almost certainly preferable to opening lots of PRs and then closing them.

FWIW I have a new version of the Windows installer coming out soon that I believe will make this a moot point, as it will work better for users with non-ASCII usernames (basically, it just sets your home directory to /home/sage so that no tools have any problem with this, but this will be mapped to your real home directory in Windows).

@vit-tucek
Copy link

@embray That's great news. Thank you. I tried installing the new version (8.2) and my fix stopped working.
My home directory is "C:\Users\Vít Tuček"

Without my patch I get

(sage-sh) Vít Tuček@ZagrebComp:~$ sage -n
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.2, Release Date: 2018-05-05                     │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
Please wait while the SageNB export server starts...
Traceback (most recent call last):
  File "/opt/sagemath-8.2/src/bin/sage-notebook", line 268, in <module>
    launcher(unknown)
  File "/opt/sagemath-8.2/src/bin/sage-notebook", line 142, in __init__
    super(SageNBExport, self).__init__(argv)
  File "/opt/sagemath-8.2/src/bin/sage-notebook", line 100, in __init__
    main(argv)
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/jupyter_core/application.py", line 266, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/traitlets/config/application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/notebook/notebookapp.py", line 1501, in initialize
    super(NotebookApp, self).initialize(argv)
  File "<decorator-gen-6>", line 2, in initialize
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/jupyter_core/application.py", line 242, in initialize
    self.migrate_config()
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/jupyter_core/application.py", line 165, in migrate_config
    if not os.path.exists(get_ipython_dir()):
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/jupyter_core/migrate.py", line 79, in get_ipython_dir
    return os.environ.get('IPYTHONDIR', os.path.expanduser('~/.ipython'))
  File "/opt/sagemath-8.2/local/lib/python2.7/posixpath.py", line 277, in expanduser
    return (userhome + path[i:]) or '/'
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)

With my patch applied.

(sage-sh) Vít Tuček@ZagrebComp:~$sage -n
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.2, Release Date: 2018-05-05                     │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
Please wait while the SageNB export server starts...
Traceback (most recent call last):
  File "/opt/sagemath-8.2/src/bin/sage-notebook", line 268, in <module>
    launcher(unknown)
  File "/opt/sagemath-8.2/src/bin/sage-notebook", line 142, in __init__
    super(SageNBExport, self).__init__(argv)
  File "/opt/sagemath-8.2/src/bin/sage-notebook", line 100, in __init__
    main(argv)
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/jupyter_core/application.py", line 266, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/traitlets/config/application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/notebook/notebookapp.py", line 1501, in initialize
    super(NotebookApp, self).initialize(argv)
  File "<decorator-gen-6>", line 2, in initialize
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/jupyter_core/application.py", line 242, in initialize
    self.migrate_config()
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/jupyter_core/application.py", line 165, in migrate_config
    if not os.path.exists(get_ipython_dir()):
  File "/opt/sagemath-8.2/local/lib/python2.7/site-packages/jupyter_core/migrate.py", line 79, in get_ipython_dir
    return os.environ.get('IPYTHONDIR', os.path.expanduser('~/.ipython'))
  File "/opt/sagemath-8.2/local/lib/python2.7/posixpath.py", line 277, in expanduser
    return (userhome + path[i:]) or '/'
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)

@embray
Copy link
Contributor Author

embray commented May 26, 2018

I haven't made a release with the aforementioned fix yet. When I do it will be in the published changelog.

@vit-tucek
Copy link

@embray The problem is that the fix (which works flawlessly in 8.1) stopped working in 8.2 and unicode exceptions pop up all over the place. Did you make any changes to Cygwin? I'd check the published changelog but I have no idea where it is. :)

@vit-tucek
Copy link

I did some more digging and it seems that the problem to line 215 in /opt/sagemath-8.2/local/lib/python2.7/site-packages/notebook/notebookapp.py, namely to

    if root_dir.startswith(home + os.path.sep):

The variable root_dir is unicode, the home is not.

Adding the following just before seems to fix the problem.

        #home = home.decode(sys.getfilesystemencoding())

@embray
Copy link
Contributor Author

embray commented Jun 1, 2018

That's still something to do with Jupyter.

@embray
Copy link
Contributor Author

embray commented Aug 10, 2018

The new SageMath 8.3 release allows you to set your default home directory for Sage at installation time, and also provides a script sage-sethome for modifying it any other time.

I'm still not sure it's ideal, but the approach I've taken of mapping your preferred home directory to the /home/sage POSIX path seems to be the safest option for most software (especially software that does not handle spaces or non-ASCII characters in home directories well).

@embray embray closed this as completed Aug 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants