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

Allow running Sage with a temporary DOT_SAGE directory #11932

Closed
jdemeyer opened this issue Oct 17, 2011 · 42 comments
Closed

Allow running Sage with a temporary DOT_SAGE directory #11932

jdemeyer opened this issue Oct 17, 2011 · 42 comments

Comments

@jdemeyer
Copy link
Contributor

Version which deals with matplotlib issue: apply

Depends on #11926

CC: @jhpalmieri

Component: scripts

Author: John Palmieri

Reviewer: Jeroen Demeyer

Merged: sage-5.1.beta0

Issue created by migration from https://trac.sagemath.org/ticket/11932

@jdemeyer
Copy link
Contributor Author

comment:1

I copied some patches from #11926 (and make some small changes to John's patch).

@jdemeyer
Copy link
Contributor Author

Dependencies: #11926

@nexttime
Copy link
Mannequin

nexttime mannequin commented Oct 17, 2011

comment:3

I'd rename the function (as it creates a temporary directory), and not use a global variable for the "return value".

The function could either take the variable name as its parameter (such that sage_make_tmp_dir DIR assigns the directory name to DIR), or just "echo" the result (as mktemp already does), such that one writes DIR=sage_make_tmp_dir or whatever.

@nexttime
Copy link
Mannequin

nexttime mannequin commented Oct 18, 2011

comment:4

Replying to @nexttime:

or just "echo" the result (as mktemp already does), such that one writes DIR=sage_make_tmp_dir or whatever.

DIR=`sage_make_tmp_dir` of course.

@jhpalmieri
Copy link
Member

comment:5

Here's a version in which the function echoes the path of the temp dir.

This works best with the patch from #11924: without applying the patch there, the parent directory of the temporary .sage directory gets polluted with pickle cache files.

@jhpalmieri

This comment has been minimized.

@jdemeyer
Copy link
Contributor Author

jdemeyer commented Nov 3, 2011

Milestone sage-4.7.3 deleted

@jdemeyer jdemeyer removed this from the sage-4.8 milestone Nov 3, 2011
@jhpalmieri
Copy link
Member

comment:7

Rebased to #11073. Documentation added.

@jhpalmieri

This comment has been minimized.

@jhpalmieri jhpalmieri added this to the sage-5.0 milestone Feb 28, 2012
@jdemeyer
Copy link
Contributor Author

Reviewer: Jeroen Demeyer

@jdemeyer
Copy link
Contributor Author

comment:8

The following seems to be portable:

mktemp -d ${TMPDIR:-/tmp}/dotsageXXXXXX

so I would use this instead of sage_mktempdir.

sage-sage needs to be replaced by sage.

Finally, why not simply run

./sage --norc </dev/null >/dev/null 2>/dev/null

in spkg-install?

@jdemeyer
Copy link
Contributor Author

Author: John Palmieri

@jdemeyer
Copy link
Contributor Author

comment:9

I meant "in spkg/install".

@jhpalmieri

This comment has been minimized.

@jhpalmieri
Copy link
Member

comment:10

Fixed. The patch to spkg/install is no longer valid; instead, we need to patch the sage-starts script.

@jhpalmieri
Copy link
Member

comment:11

This is not working, and I'm probably making some bash error in the sage script. When I run

sage -c 'print "hello"'

it works as it should: no banner, just "hello", then a new shell prompt. When I run

sage --norc -c 'print "hello"'

it starts up Sage, prints a banner, prints "hello", and then gives the Sage prompt. As a consequence, the sage-starts script is not working right. What am I doing wrong?

@jdemeyer
Copy link
Contributor Author

comment:19

On an entirely different topic: I don't like the --norc option name. In the light of #12647, I would expect that option to suppress the reading of the sagerc script (and/or the init.sage script). I would only support --nodotsage.

@jhpalmieri
Copy link
Member

comment:20

Here are new patches which just use --nodotsage. (I also considered --tmpdotsage, but it doesn't matter too much, as long as it's documented.)

@jhpalmieri
Copy link
Member

Attachment: trac_11932-scripts.patch.gz

scripts repo

@jhpalmieri
Copy link
Member

documentation patch (Sage library)

@nexttime
Copy link
Mannequin

nexttime mannequin commented Mar 19, 2012

comment:21

Attachment: trac_11932-doc.patch.gz

It would be nice to also have --nosagerc, and let --nodotsage by default not bypass [$DOT_SAGE/]sagerc (if it exists; of course no directory should be created if it doesn't).

@jhpalmieri
Copy link
Member

comment:22

Perhaps on another ticket...

@jdemeyer
Copy link
Contributor Author

jdemeyer commented Apr 9, 2012

comment:23

Unfortunately, this doesn't quite work properly since DOT_SAGE is changed after reading sage-env. The following variables still refer to $HOME/.sage:

jdemeyer@arcanis:/usr/local/src/sage-5.0.beta13$ ./sage --nodotsage --sh -c env | fgrep "$HOME/.sage"
MPLCONFIGDIR=/home/jdemeyer/.sage//matplotlib-1.1.0
SAGE_STARTUP_FILE=/home/jdemeyer/.sage//init.sage
SAGE_TESTDIR=/home/jdemeyer/.sage//tmp

I suggest moving the --nodotsage check before the sourcing of sage-env.

@jhpalmieri
Copy link
Member

comment:25

Okay, here's a new root patch.

@jdemeyer
Copy link
Contributor Author

comment:26

Just one more issue: now that you don't source sage-env, the command sage looks for sage in the system PATH. I suggest to replace

command sage "$@"

by

command "$0" "$@"

If you make this change, you can give this ticket positive review.

Furthermore, I would like to point out that $HOME/.sage/matplotlib-1.1.0 is still created by sage-env when building Sage. But that shouldn't stop this ticket.

@jhpalmieri
Copy link
Member

root repo

@jhpalmieri
Copy link
Member

Attachment: trac_11932-root.patch.gz

@jhpalmieri

This comment has been minimized.

@jhpalmieri
Copy link
Member

comment:27

Attachment: trac_11932-root.v2.patch.gz

Here are two versions. If we want the easy root, the first version just makes the change

diff --git a/spkg/bin/sage b/spkg/bin/sage
--- a/spkg/bin/sage
+++ b/spkg/bin/sage
@@ -238,7 +238,7 @@ cd "$SAGE_ROOT"
 if [ "$1" = '--nodotsage' ]; then
     export DOT_SAGE=`mktemp -d ${TMPDIR:-/tmp}/dotsageXXXXXX`
     shift
-    command sage "$@"
+    command "$0" "$@"
     status=$?
     rm -rf "$DOT_SAGE"
     exit $status

The second version deals (I think) with the matplotlib issue, creating the config directory in sage.misc.misc, where other subdirectories of DOT_SAGE are created. It's not a very significant difference: the file attachment: trac_11932-sage.v2.patch and these changes to the root patch:

diff --git a/spkg/bin/sage-env b/spkg/bin/sage-env
--- a/spkg/bin/sage-env
+++ b/spkg/bin/sage-env
@@ -281,8 +281,9 @@ fi
 
 if [ "$DOT_SAGE" = "" ]; then
     # It is *not* an error if this directory does not exist, it will
-    # be created in spkg/bin/sage.  This also works if $HOME/.sage is a
-    # symbolic link to a non-existing directory.
+    # be created in spkg/bin/sage or devel/sage/sage/misc/misc.py.
+    # This also works if $HOME/.sage is a symbolic link to a
+    # non-existing directory.
     DOT_SAGE=`resolvelinks "$HOME/.sage"`
 
     # In theory, DOT_SAGE is not required to have a trailing slash.
@@ -340,8 +341,7 @@ if [ -f "$MPLINITFILE" ]; then
         MPLCONFIGDIR="$DOT_SAGE/matplotlib"
     fi
     export MPLCONFIGDIR
-    # Create the directory, because matplotlib doesn't seem to be happy otherwi
-    mkdir -p "$MPLCONFIGDIR"
+    # The directory is created when Sage starts (see sage.misc.misc).
 fi
 
 # Add some directories to $LD_LIBRARY_PATH:

If you have time to look at the second version, please consider it. If you would rather deal with just the first version here, we can move the other version to a new ticket.

@jdemeyer
Copy link
Contributor Author

jdemeyer commented May 7, 2012

comment:28

For the Sage patch, what about:

try:
    # Create the matplotlib config directory
    sage_makedirs(os.environ["MPLCONFIGDIR"])
except KeyError:
    pass

I don't see a reason to create a directory when the environment variable doesn't exist.

@jdemeyer jdemeyer modified the milestones: sage-5.0, sage-5.1 May 7, 2012
@jhpalmieri
Copy link
Member

comment:29

Since we set MPLCONFIGDIR in sage-env, there is no reason for it not to be set (unless someone does something risky and unsupported like try to import the Sage library using the system's Python). But I made the change anyway.

@jdemeyer
Copy link
Contributor Author

jdemeyer commented May 8, 2012

comment:30

Attachment: trac_11932-sage.v2.patch.gz

Looks good and works well.

I'm currently running

sage --nodotsage -tp 2 devel/sage/sage

@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link
Contributor Author

jdemeyer commented May 8, 2012

comment:31
All tests passed!

@jdemeyer
Copy link
Contributor Author

Merged: sage-5.1.beta0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants