Ticket #12719: 12719-system.patch

File 12719-system.patch, 2.9 KB (added by jason, 9 years ago)

apply to sage repository

  • sage/misc/interpreter.py

    # HG changeset patch
    # User Jason Grout <jason.grout@drake.edu>
    # Date 1352842535 21600
    # Node ID e0220350d70e6f4a1d4906c48ba9e9241fd6adc1
    # Parent  a90938935377ca686063a13a90c615c9b9e61881
    Make the system_raw method *actually* adjust the libraries.
    
    Thanks also to Jeroen Demeyer for pointing out problems with the
    exit code tests and other problems with this function.
    
    diff --git a/sage/misc/interpreter.py b/sage/misc/interpreter.py
    a b  
    161161
    162162    def system_raw(self, cmd):
    163163        """
    164         Adjust the libraries before calling system commands.  See Trac
    165         #975 for a discussion of this function.
     164        Run a system command.
     165
     166        If the command is not a sage-specific binary, adjust the library paths before calling
     167        system commands.  See Trac #975 for a discussion of running system commands.
     168
     169        This is equivalent to the sage-native-execute shell script.
    166170
    167171        EXAMPLES::
    168172       
    169173            sage: from sage.misc.interpreter import get_test_shell
    170174            sage: shell = get_test_shell()
    171175            sage: shell.system_raw('false')
    172             sage: shell.user_ns['_exit_code']
    173             256
     176            sage: status = shell.user_ns['_exit_code']
     177            sage: os.WIFEXITED(status) and os.WEXITSTATUS(status) != 0
     178            True
     179            sage: shell.system_raw('true')
     180            sage: status = shell.user_ns['_exit_code']
     181            sage: os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0
     182            True
     183            sage: shell.system_raw('env | grep "^LD_LIBRARY_PATH=" | grep $SAGE_LOCAL')
     184            sage: status = shell.user_ns['_exit_code']
     185            sage: os.WIFEXITED(status) and os.WEXITSTATUS(status) != 0
     186            True
     187            sage: shell.system_raw('R --version')
     188            sage: status = shell.user_ns['_exit_code']
     189            sage: os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0
     190            True
    174191        """
    175         sage_commands = os.listdir(os.environ['SAGE_ROOT']+"/local/bin/")
    176         DARWIN_SYSTEM = os.uname()[0]=='Darwin'
    177         if cmd in sage_commands:
    178             return super(SageInteractiveShell, self).system_raw(cmd)
    179         else:
    180             libraries = 'LD_LIBRARY_PATH=$$SAGE_ORIG_LD_LIBRARY_PATH;'
    181             if DARWIN_SYSTEM:
    182                 libraries += 'DYLD_LIBRARY_PATH=$$SAGE_ORIG_DYLD_LIBRARY_PATH;'
    183             return super(SageInteractiveShell, self).system_raw(cmd)
     192        path = os.path.join(os.environ['SAGE_LOCAL'],'bin',cmd.split(' |\n\t;&',1)[0])
     193        if not os.access(path, os.X_OK):
     194            libraries = 'LD_LIBRARY_PATH="$SAGE_ORIG_LD_LIBRARY_PATH";export LD_LIBRARY_PATH;'
     195            if os.uname()[0]=='Darwin':
     196                libraries += 'DYLD_LIBRARY_PATH="$SAGE_ORIG_DYLD_LIBRARY_PATH";export DYLD_LIBRARY_PATH;'
     197            cmd = libraries+cmd
     198        return super(SageInteractiveShell, self).system_raw(cmd)
    184199
    185200    def ask_exit(self):
    186201        """