#9811: `sage -i ...` exits with 0, even if it is unable to install a package.
------------------------+---------------------------------------------------
   Reporter:  drkirkby  |          Owner:  GeorgSWeber                          
      
       Type:  defect    |         Status:  needs_review                         
      
   Priority:  major     |      Milestone:  sage-4.7.2                           
      
  Component:  scripts   |       Keywords:  sage-sage return code status 
pipestatus tee
Work_issues:            |       Upstream:  N/A                                  
      
   Reviewer:            |         Author:  Leif Leonhardy                       
      
     Merged:            |   Dependencies:  #10157                               
      
------------------------+---------------------------------------------------
Changes (by newvalueoldvalue):

  * status:  new => needs_review
  * author:  => Leif Leonhardy
  * component:  build => scripts
  * dependencies:  => #10157
  * keywords:  => sage-sage return code status pipestatus tee


Old description:

> I wanted to do some testing of Sage in a loop and would check the return
> code to see if what I used worked or not. But this is impossible, as Sage
> appears to exit with 0, even if it should not have. In the example below,
> I try to install a non-existent package using Sage. The return code in a
> case like this should be non-zero, but it is not.
>
> {{{
> drkirkby@hawk:~/sage-4.5.2$ ./sage -f some-non-existant-package
> Force installing some-non-existant-package
> Calling sage-spkg on some-non-existant-package
> Warning: Attempted to overwrite SAGE_ROOT environment variable
> Building Sage on Solaris in 64-bit mode
> Creating SAGE_LOCAL/lib/sage-64.txt since it does not exist
> Detected SAGE64 flag
> Building Sage on Solaris in 64-bit mode
> some-non-existant-package
> Machine:
> SunOS hawk 5.11 snv_134 i86pc i386 i86pc
> Deleting directories from past builds of previous/current versions of
> some-non-existant-package
> /export/home/drkirkby/sage-4.5.2/local/bin/sage-spkg: file some-non-
> existant-package does not exist
> Attempting to download it.
> http://www.sagemath.org//packages/optional/some-non-existant-package.spkg
> --> some-non-existant-package.spkg
> [ ]
> http://www.sagemath.org//packages/standard/some-non-existant-package.spkg
> --> some-non-existant-package.spkg
> [ ]
> http://www.sagemath.org//packages/experimental/some-non-existant-
> package.spkg --> some-non-existant-package.spkg
> [ ]
> http://www.sagemath.org//packages/archive/some-non-existant-package.spkg
> --> some-non-existant-package.spkg
> [ ]
> **********************************************************************
> * Unable to download some-non-existant-package
> * Please see http://www.sagemath.org//packages for a list of valid
> * packages or check the package name.
> **********************************************************************
> sage: Failed to download package some-non-existant-package from
> http://www.sagemath.org/
> drkirkby@hawk:~/sage-4.5.2$ $?
> bash: 0: command not found
> drkirkby@hawk:~/sage-4.5.2$
> }}}
>
> The same happens if one uses {{{sage -i}}} to install a package. If it
> fails, the exit code is still 0.
>
> In contrast, if I try this with a well written command like {{{ls}}}
>
> {{{
> drkirkby@hawk:~/sage-4.5.2$ ls some-non-existant-package
> some-non-existant-package: No such file or directory
> drkirkby@hawk:~/sage-4.5.2$ $?
> bash: 2: command not found
> }}}
>
> the exit code is non-zero - in this case 2.
>
> ----
>
> Also on a similar theme is #9799, showing that {{{make}}} can exit with
> the wrong code too.
>
> ----
>
> Dependency: #10157

New description:

 I wanted to do some testing of Sage in a loop and would check the return
 code to see if what I used worked or not. But this is impossible, as Sage
 appears to exit with 0, even if it should not have. In the example below,
 I try to install a non-existent package using Sage. The return code in a
 case like this should be non-zero, but it is not.

 {{{
 drkirkby@hawk:~/sage-4.5.2$ ./sage -f some-non-existant-package
 Force installing some-non-existant-package
 Calling sage-spkg on some-non-existant-package
 Warning: Attempted to overwrite SAGE_ROOT environment variable
 Building Sage on Solaris in 64-bit mode
 Creating SAGE_LOCAL/lib/sage-64.txt since it does not exist
 Detected SAGE64 flag
 Building Sage on Solaris in 64-bit mode
 some-non-existant-package
 Machine:
 SunOS hawk 5.11 snv_134 i86pc i386 i86pc
 Deleting directories from past builds of previous/current versions of
 some-non-existant-package
 /export/home/drkirkby/sage-4.5.2/local/bin/sage-spkg: file some-non-
 existant-package does not exist
 Attempting to download it.
 http://www.sagemath.org//packages/optional/some-non-existant-package.spkg
 --> some-non-existant-package.spkg
 [ ]
 http://www.sagemath.org//packages/standard/some-non-existant-package.spkg
 --> some-non-existant-package.spkg
 [ ]
 http://www.sagemath.org//packages/experimental/some-non-existant-
 package.spkg --> some-non-existant-package.spkg
 [ ]
 http://www.sagemath.org//packages/archive/some-non-existant-package.spkg
 --> some-non-existant-package.spkg
 [ ]
 **********************************************************************
 * Unable to download some-non-existant-package
 * Please see http://www.sagemath.org//packages for a list of valid
 * packages or check the package name.
 **********************************************************************
 sage: Failed to download package some-non-existant-package from
 http://www.sagemath.org/
 drkirkby@hawk:~/sage-4.5.2$ $?
 bash: 0: command not found
 drkirkby@hawk:~/sage-4.5.2$
 }}}

 The same happens if one uses {{{sage -i}}} to install a package. If it
 fails, the exit code is still 0.

 In contrast, if I try this with a well written command like {{{ls}}}

 {{{
 drkirkby@hawk:~/sage-4.5.2$ ls some-non-existant-package
 some-non-existant-package: No such file or directory
 drkirkby@hawk:~/sage-4.5.2$ $?
 bash: 2: command not found
 }}}

 the exit code is non-zero - in this case 2.

 ----

 Also on a similar theme is #9799, showing that {{{make}}} can exit with
 the wrong code too.

 ----

 Apply
  1. [attachment:trac_9811-use_pipestatus_in_sage-sage.scripts.patch]
 to the Sage '''scripts repository'''.

--

Comment:

 Attached patch fixes the exit code (by using `pipestatus`) and a few minor
 things in that area of `sage-sage`.

 (I haven't changed more since there are other tickets already touching
 `sage-sage` especially there, which may need ''slight'' rebasing on the
 patch here though.)

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/9811#comment:7>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to