Sage: Ticket #13459: spkg/bin/sage: do not change directory
https://trac.sagemath.org/ticket/13459
<p>
Remove all unneeded "cd" statements from <code>spkg/bin/sage</code>.
</p>
<p>
Apply:
</p>
<ol><li><a class="attachment" href="https://trac.sagemath.org/attachment/ticket/13459/13459_no_cd.patch" title="Attachment '13459_no_cd.patch' in Ticket #13459">13459_no_cd.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/13459/13459_no_cd.patch" title="Download"></a> to the SAGE_ROOT repository.
</li><li><a class="attachment" href="https://trac.sagemath.org/attachment/ticket/13459/13459_no_cd_scripts.patch" title="Attachment '13459_no_cd_scripts.patch' in Ticket #13459">13459_no_cd_scripts.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/13459/13459_no_cd_scripts.patch" title="Download"></a> to the SCRIPTS repository.
</li></ol>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/13459
Trac 1.1.6jdemeyerThu, 13 Sep 2012 13:57:15 GMTdescription, summary changed
https://trac.sagemath.org/ticket/13459#comment:1
https://trac.sagemath.org/ticket/13459#comment:1
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/13459?action=diff&version=1">diff</a>)
</li>
<li><strong>summary</strong>
changed from <em>sage_setup() in spkg/bin/sage: do not change directory</em> to <em>spkg/bin/sage: do not change directory</em>
</li>
</ul>
TicketjdemeyerThu, 13 Sep 2012 15:16:12 GMTstatus, description changed
https://trac.sagemath.org/ticket/13459#comment:2
https://trac.sagemath.org/ticket/13459#comment:2
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>description</strong>
modified (<a href="/ticket/13459?action=diff&version=2">diff</a>)
</li>
</ul>
TicketjdemeyerSun, 16 Sep 2012 19:04:09 GMTattachment set
https://trac.sagemath.org/ticket/13459
https://trac.sagemath.org/ticket/13459
<ul>
<li><strong>attachment</strong>
set to <em>13459_no_cd.patch</em>
</li>
</ul>
TicketjdemeyerWed, 19 Sep 2012 06:41:54 GMTstatus changed
https://trac.sagemath.org/ticket/13459#comment:3
https://trac.sagemath.org/ticket/13459#comment:3
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
</ul>
<p>
There is a problem with
</p>
<pre class="wiki">import sage
</pre><p>
when the current directory is <code>$SAGE_ROOT/devel/sage</code> (or more generally, when a directory <code>sage</code> exists).
</p>
TicketjdemeyerTue, 25 Sep 2012 19:47:56 GMTstatus changed
https://trac.sagemath.org/ticket/13459#comment:4
https://trac.sagemath.org/ticket/13459#comment:4
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_review</em>
</li>
</ul>
TicketjhpalmieriTue, 25 Sep 2012 22:30:01 GMT
https://trac.sagemath.org/ticket/13459#comment:5
https://trac.sagemath.org/ticket/13459#comment:5
<p>
Why are there still some "cd"s in spkg/bin/sage? At least some of them (sync-build, bdist, upgrade) don't look like they're needed. I don't know about the patchbot.
</p>
TicketjdemeyerTue, 25 Sep 2012 22:35:38 GMT
https://trac.sagemath.org/ticket/13459#comment:6
https://trac.sagemath.org/ticket/13459#comment:6
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/13459#comment:5" title="Comment 5">jhpalmieri</a>:
</p>
<blockquote class="citation">
<p>
Why are there still some "cd"s in spkg/bin/sage? At least some of them (sync-build, bdist, upgrade) don't look like they're needed. I don't know about the patchbot.
</p>
</blockquote>
<p>
I wanted to err on the safe side. When unsure, I put the <code>cd</code> statement (or left it). <code>bdist</code> seems to require the <code>cd</code>, for the rest I don't know.
</p>
TicketjhpalmieriWed, 26 Sep 2012 23:12:10 GMT
https://trac.sagemath.org/ticket/13459#comment:7
https://trac.sagemath.org/ticket/13459#comment:7
<p>
Can you explain the change in sage-ipython? I don't see any lines corresponding to <code>import sage</code> in the old version. I guess I don't know the mechanics of how sage gets imported when you run <code>sage</code> from the command line.
</p>
TicketjdemeyerThu, 27 Sep 2012 06:47:24 GMT
https://trac.sagemath.org/ticket/13459#comment:8
https://trac.sagemath.org/ticket/13459#comment:8
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/13459#comment:7" title="Comment 7">jhpalmieri</a>:
</p>
<blockquote class="citation">
<p>
Can you explain the change in sage-ipython? I don't see any lines corresponding to <code>import sage</code> in the old version. I guess I don't know the mechanics of how sage gets imported when you run <code>sage</code> from the command line.
</p>
</blockquote>
<p>
When running Sage through IPython (but not through plain Python when running a script for example), the current working directory is always added to <code>sys.path</code> (the empty string is added as zeroth entry, which means the current working directory). So when doing
</p>
<pre class="wiki">import sage # or sage.foo.bar....
</pre><p>
the <em>current working directory</em> will be checked first for the existence of a "sage" module. If the current working directory happens to be <code>$SAGE_ROOT/devel/sage</code>, that contains a "sage" subdirectory which Python will happily import. But this is the wrong directory, it should be imported from <code>site-packages</code> instead. This creates problems for Cython modules, as these exist <em>only</em> in <code>site-packages</code>.
</p>
<p>
So we avoid this problem by first fixing <code>sys.path</code>, then importing Sage so any future imports of Sage submodules will work fine.
</p>
TicketjdemeyerThu, 27 Sep 2012 06:54:34 GMTattachment set
https://trac.sagemath.org/ticket/13459
https://trac.sagemath.org/ticket/13459
<ul>
<li><strong>attachment</strong>
set to <em>13459_no_cd_scripts.patch</em>
</li>
</ul>
TicketjdemeyerThu, 27 Sep 2012 06:55:26 GMT
https://trac.sagemath.org/ticket/13459#comment:9
https://trac.sagemath.org/ticket/13459#comment:9
<p>
I just realized that there is no need to change <code>sys.path</code> in <code>sage-ipython</code>, because we simply import <code>sage</code> before IPython is started. I also added some more comments, needs_review.
</p>
TicketjhpalmieriThu, 27 Sep 2012 19:03:04 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/13459#comment:10
https://trac.sagemath.org/ticket/13459#comment:10
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>reviewer</strong>
set to <em>John Palmieri</em>
</li>
</ul>
<p>
Okay, this looks pretty good to me. I might prefer some more comments in spkg/bin/sage, for example pointing out that sage-bdist needs to be run from SAGE_ROOT. (I'm not actually sure that it does, actually: if run from somewhere else, it just creates the temporary directories in the current working directory, but maybe it will still work. I guess for the principle of least surprise, we shouldn't change the behavior of building in SAGE_ROOT/tmp/.)
</p>
TicketjdemeyerFri, 28 Sep 2012 07:49:18 GMTstatus changed; resolution, merged set
https://trac.sagemath.org/ticket/13459#comment:11
https://trac.sagemath.org/ticket/13459#comment:11
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>merged</strong>
set to <em>sage-5.4.rc0</em>
</li>
</ul>
Ticket