Ticket #11602: trac_11602-delta2to3.patch

File trac_11602-delta2to3.patch, 5.5 KB (added by John Palmieri, 11 years ago)

for reference only; do not apply

  • sage/misc/dist.py

    diff --git a/sage/misc/dist.py b/sage/misc/dist.py
    a b def install_scripts(directory=None, igno 
    88    r"""
    99    Running ``install_scripts(directory)`` creates scripts in the
    1010    given directory that run various software components included with
    11     Sage: 'gap', 'gp', 'singular', 'maxima', 'M2', 'kash', 'mwrank',
    12     'ipython', 'hg', 'R'.
     11    Sage.  Each of these scripts essentially just runs ``sage --CMD``
     12    where ``CMD`` is also the name of the script:
     13
     14    - 'gap' runs GAP
     15    - 'gp' runs the PARI/GP interpreter
     16    - 'hg' runs Mercurial
     17    - 'ipython' runs IPython
     18    - 'maxima' runs Maxima
     19    - 'mwrank' runs mwrank
     20    - 'R' runs R
     21    - 'singular' runs Singular
     22    - 'kash' runs Kash if it is installed (Kash is an optional Sage
     23      package)
     24    - 'M2' runs Macaulay2 if it is installed (Macaulay2 is an
     25      experimental Sage package)
    1326   
    1427    This command:
    1528   
    def install_scripts(directory=None, igno 
    2134    INPUT:
    2235
    2336    - ``directory`` - string; the directory into which to put the
    24        scripts
     37      scripts.  This directory must exist and the user must have write
     38      and execute permissions.
    2539
    2640    - ``ignore_existing`` - bool (optional, default False): if True,
    2741      install script even if another version of the program is in your
    def install_scripts(directory=None, igno 
    3246   
    3347    .. note::
    3448
    35        You may need to run Sage as root in order to run
    36        ``install_scripts`` successfully, since the user running Sage
    37        will need write permissions on ``directory``.  Note that
    38        one good candidate for ``directory`` is ``'/usr/local/bin'``.
     49       You may need to run ``sage`` as ``root`` in order to run
     50       ``install_scripts`` successfully, since the user running
     51       ``sage`` needs write permissions on ``directory``.  Note
     52       that one good candidate for ``directory`` is
     53       ``'/usr/local/bin'``, so from the shell prompt, you could run ::
     54
     55           sudo sage -c "install_scripts('/usr/local/bin')"
    3956
    4057    .. note::
    4158
    def install_scripts(directory=None, igno 
    5471
    5572        sage: install_scripts(SAGE_TMP, ignore_existing=True)
    5673        Checking that Sage has the command 'gap' installed
    57         Created script ...
     74        ...
    5875    """
    5976    if directory is None:
    6077        # We do this since the intended user of install_scripts
    def install_scripts(directory=None, igno 
    6279        # its help system.
    6380        import sagedoc
    6481        print sagedoc.format(install_scripts.__doc__)
    65         print "USAGE: install_scripts('bin directory name')"
     82        print "USAGE: install_scripts('directory')"
    6683        return
    6784   
    68     if not (os.path.exists(directory) and os.path.isdir(directory)):
    69         raise OSError, "'%s' must exist and be a directory"%directory
     85    if not os.path.exists(directory):
     86        print "Error: '%s' does not exist." % directory
     87        return
     88
     89    if not os.path.isdir(directory):
     90        print "Error: '%s' is not a directory." % directory
     91        return
     92
     93    if not (os.access(directory, os.W_OK) and os.access(directory, os.X_OK)):
     94        print "Error: you do not have write permission for '%s'." % directory
     95        return
    7096
    7197    script_created = False
    7298
    73     for cmd in ['gap', 'gp', 'singular', 'maxima', 'M2', 'kash', \
    74               'mwrank', 'ipython', 'hg', 'R']:
     99    SAGE_ROOT = os.environ['SAGE_ROOT']
     100    SAGE_BIN = os.path.join(SAGE_ROOT, 'local', 'bin')
     101    # See if 'directory' is already in PATH, and then remove
     102    # SAGE_ROOT/local/bin from PATH so that we can later check whether
     103    # cmd is available outside of Sage.
     104    PATH = os.environ['PATH'].split(os.pathsep)
     105    PATH = [d for d in PATH if os.path.exists(d)]
     106    dir_in_path = any([os.path.samefile(directory, d) for d in PATH])
     107    PATH = os.pathsep.join([d for d in PATH if not
     108                            os.path.samefile(d, SAGE_BIN)])
     109    for cmd in ['gap', 'gp', 'hg', 'ipython', 'maxima',
     110              'mwrank', 'R', 'singular', 'M2', 'kash']:
    75111        print "Checking that Sage has the command '%s' installed" % cmd
    76112        from sage.misc.sage_ostools import have_program
    77         SAGE_ROOT = os.environ['SAGE_ROOT']
    78         SAGE_BIN = os.path.join(SAGE_ROOT, 'local', 'bin')
    79113        # Check to see if Sage includes cmd.
    80114        cmd_inside_sage = have_program(cmd, path=SAGE_BIN)
    81         # Remove SAGE_ROOT/local/bin from the path and check
    82         # whether cmd is still available:
    83         PATH = os.environ['PATH'].split(os.pathsep)
    84         PATH = os.pathsep.join([d for d in PATH if os.path.exists(d)
    85                          and not os.path.samefile(d, SAGE_BIN)])
    86115        cmd_outside_sage = have_program(cmd, path=PATH)
    87116        if not cmd_inside_sage:
    88             print "The command '%s' is not available as part " %cmd \
    89                   + "of Sage; not creating script."
     117            print ("The command '%s' is not available as part " %cmd
     118                   + "of Sage; not creating script.")
    90119            print
    91120            continue
    92121        if cmd_outside_sage:
    def install_scripts(directory=None, igno 
    118147        print "You need not do this again even if you upgrade or move Sage."
    119148        print "The only requirement is that your PATH contains both"
    120149        print "'%s' and the directory containing the command 'sage'." % directory
     150        if not dir_in_path:
     151            print
     152            print "Warning: '%s' is not currently in your PATH." % directory
     153            print
    121154    else:
    122155        print "No scripts created."