Bug: Python scripts try to run before Python is built.

4 views
Skip to first unread message

Dr. David Kirkby

unread,
Sep 23, 2010, 11:14:07 AM9/23/10
to sage-devel
Readline is a package which has no dependences other than BASE (see
$SAGE_ROOT/spkg/standard/deps). So it can be built very early - before Python.

This is part of the log from a successful installation of readline.

=================================================================
-bash-4.1$ tail spkg/logs/readline-6.0.p2.log
make[2]: Leaving directory
`/home/users/drkirkby/sage-4.6.alpha1/spkg/build/readline-6.0.p2/src'

real 8m1.326s
user 4m33.895s
sys 0m50.145s
Successfully installed readline-6.0.p2
Now cleaning up tmp files.
Making Sage/Python scripts relocatable...
python: No such file or directory
Finished installing readline-6.0.p2.spkg
==================================================================

Notice two of the last last 3 lines above say

Making Sage/Python scripts relocatable...
python: No such file or directory

William created
http://trac.sagemath.org/sage_trac/ticket/9507

to check that SAGE_LOCAL/bin/python exists before running any packages that have
spkg-install in them, but there's nothing to stop Sage trying to run python
scrips before Python is installed.

As we found on bsd.math, a slightly broken version of Python caused all sorts of
problems when sage_fortran got screwed up.

Clearly Python is not installed on this system, as we can test in two ways.

1) The portable (POSIX compatible test)
-bash-4.1$ command -v python

2) The non-portable (non POSIX) test you are probably more familiar with.
-bash-4.1$ which python
which: 0652-141 There is no python in /opt/pware/bin /usr/bin /etc /usr/sbin
/usr/ucb /home/users/drkirkby/bin /usr/bin/X11 /sbin ..


So there's no Python installed on this system, but Sage has generated messages
that python does not exist, and that its making Sage/Python scripts relocatable,
before it has built Python.

This I believe is a bug, which was unsurprisingly found when trying to build
Sage on a less popular operating system (AIX).

Dave

John H Palmieri

unread,
Sep 23, 2010, 11:29:54 AM9/23/10
to sage-devel


On Sep 23, 8:14 am, "Dr. David Kirkby" <david.kir...@onetel.net>
wrote:
> Readline is a package which has no dependences other than BASE (see
> $SAGE_ROOT/spkg/standard/deps). So it can be built very early - before Python.
>
> This is part of the log from a successful installation of readline.
>
> =================================================================
> -bash-4.1$ tail spkg/logs/readline-6.0.p2.log
> make[2]: Leaving directory
> `/home/users/drkirkby/sage-4.6.alpha1/spkg/build/readline-6.0.p2/src'
>
> real    8m1.326s
> user    4m33.895s
> sys     0m50.145s
> Successfully installed readline-6.0.p2
> Now cleaning up tmp files.
> Making Sage/Python scripts relocatable...
> python: No such file or directory
> Finished installing readline-6.0.p2.spkg
> ==================================================================
>
> Notice two of the last last 3 lines above say
>
> Making Sage/Python scripts relocatable...
> python: No such file or directory

This is from the script sage-spkg:

echo "Making Sage/Python scripts relocatable..."

cd "$SAGE_LOCAL"/bin
./sage-make_relative

Then sage-make_relative is a python script.

Maybe this part of the script should test for python's existence
first, and if it's there, run it. Or test for the existence of both
local/bin/python/... and python?

--
John

Dr. David Kirkby

unread,
Sep 23, 2010, 12:13:26 PM9/23/10
to sage-...@googlegroups.com

But what if Python does not exist? We probably can't build it at this point, as
I doubt all Python's perquisites are in place.

This is the complete file, which is only 29 lines long.

=====================================================
drkirkby@hawk:~/sage-4.6.alpha1$ cat ./spkg/base/sage-make_relative
#!/usr/bin/env python

import os

print "Making script relocatable"
for F in os.listdir('.'):
if F == 'sage-sage':
continue
if not os.path.isfile(F):
continue
try:
X = open(F,'r')
except IOError:
continue
L = X.readline()
if L.find("python") != -1 and L.find("#!") != -1:
Y = X.read()
X.close()
#print "Making interpreter for script %s relative"%F
try:
O = open(F,'w')
except IOError:
os.system('chmod u+w "%s"'%F)
O = open(F,'w')
O.write("#!/usr/bin/env python\n"+Y)
O.close()
==========================================================


I'm not a Python guru, but the first 12 lines seem to just try to check if
"sage-sage" can be opened for reading. Is it me, or is that Python overly
complicated?

I could easily do with:

if [ -r "sage-sage" ]

in a shell script.

I'd have to try to work out what the rest of this Python does, but at only 29
lines, I doubt it would be hard to rewrite this as a more portable shell script.

It looks like it creates the pyton script at the end, with the contents of just
"#!/usr/bin/env python"

Dave

Dr. David Kirkby

unread,
Sep 23, 2010, 12:39:53 PM9/23/10
to sage-...@googlegroups.com
On 09/23/10 04:29 PM, John H Palmieri wrote:

>> Notice two of the last last 3 lines above say
>>
>> Making Sage/Python scripts relocatable...
>> python: No such file or directory
>
> This is from the script sage-spkg:
>
> echo "Making Sage/Python scripts relocatable..."
>
> cd "$SAGE_LOCAL"/bin
> ./sage-make_relative
>
> Then sage-make_relative is a python script.
>
> Maybe this part of the script should test for python's existence
> first, and if it's there, run it. Or test for the existence of both
> local/bin/python/... and python?
>
> --
> John
>

Looking at the comments on the end, it makes no difference if this works or not
before Python is built. I think testing for $SAGE_LOCAL/bin/python is probably
the best solution. I would not test for a system python, in case there's a
broken installation of Python, in which case it's anyones guess what will
happen. This error message is apparently harmless, but it's a bit dumb to have
confusing error messages.

===========================================================


echo "Making Sage/Python scripts relocatable..."

cd "$SAGE_LOCAL"/bin
./sage-make_relative

echo "Finished installing $PKG_NAME.spkg"

# It's OK if the above fails -- in fact it will until Python
# itself gets installed. That's fine.
exit 0
==========================================================

I think just adding an

if [ -f "$SAGE_LOCAL/bin/pthon" ]

around the last few lines would avoid the error message.


Dave

John H Palmieri

unread,
Sep 23, 2010, 12:55:48 PM9/23/10
to sage-devel
The script searches the files in the current directory, checking
whether the first line contains "python" and "#!". If so, it replaces
that line with "#!/usr/bin/env python". So if the package has
installed a python script, this makes sure it calls Sage's python. I
suppose it is possible that a package could install a python script
(e.g. for its front end) without python being present on the system
yet.

So rewriting it using bash or sh or perl or some other prerequisite
might make the most sense.

John


On Sep 23, 9:39 am, "Dr. David Kirkby" <david.kir...@onetel.net>
wrote:

David Kirkby

unread,
Sep 23, 2010, 2:37:17 PM9/23/10
to sage-...@googlegroups.com
On 23 September 2010 17:55, John H Palmieri <jhpalm...@gmail.com> wrote:
> The script searches the files in the current directory, checking
> whether the first line contains "python" and "#!".  If so, it replaces
> that line with "#!/usr/bin/env python".  So if the package has
> installed a python script, this makes sure it calls Sage's python.  I
> suppose it is possible that a package could install a python script
> (e.g. for its front end) without python being present on the system
> yet.
>
> So rewriting it using bash or sh or perl or some other prerequisite
> might make the most sense.
>
>  John

Thank you John.

In that case, I think it's better to just remove 29-line
'sage-make_relative' completely and move its functionality to the
426-line bash script ((sage-spkg) that calls 'sage-make_relative'

It makes no sense to me to call one script from another like this.

Reply all
Reply to author
Forward
0 new messages