Ticket #11021: trac_11021-fix_sage.misc.install_package.sagelib.patch

File trac_11021-fix_sage.misc.install_package.sagelib.patch, 3.6 KB (added by jdemeyer, 7 years ago)

Patch for the Sage library

  • sage/misc/package.py

    # HG changeset patch
    # User Leif Leonhardy <not.really@online.de>
    # Date 1310122453 -7200
    # Node ID b972c54ef93e112fa7fca6d897ed7ce103b552f7
    # Parent  bd7436d1d0753624ba449cd8c880bc008249ee84
    sage.misc.install_package(): use os.listdir() to get a list of installed packages.
    Better documentation, add examples.
    
    diff --git a/sage/misc/package.py b/sage/misc/package.py
    a b  
    105105   
    106106    INPUT:
    107107   
     108    -  ``package`` -- optional; if specified, install the
     109       given package. If not, list all installed packages.
     110
     111    - ``force`` -- boolean (default: ``False``); if ``True``, reinstall
     112      the package given if it is already installed. (Otherwise, an already
     113      installed package doesn't get reinstalled, as with 'sage -i ...'.)
     114
     115    EXAMPLES:
     116
     117    With no arguments, list the installed packages::
     118
     119        sage: install_package()
     120        ['atlas...', 'blas...', ...]
     121
     122    With an argument, install the named package::
     123
     124        sage: install_package('chomp')  # not tested
     125        Attempting to download package chomp-20100213.p2
     126        ...
     127
     128    IMPLEMENTATION:
    108129   
    109     -  ``package`` - optional; if specified, install the
    110        given package. If not, list all installed packages.
    111    
    112    
    113     IMPLEMENTATION: calls 'sage -f'.
     130    Calls 'sage -f ...' to (re)install the package if a package name is
     131    given. If no package name is given, simply list the contents of
     132    ``spkg/installed``.
    114133
    115134    .. seealso:: :func:`optional_packages`, :func:`upgrade`
    116135    """
     
    118137    if os.uname()[0][:6] == 'CYGWIN' and package is not None:
    119138        print "install_package may not work correctly under Microsoft Windows"
    120139        print "since you can't change an opened file.  Quit all"
    121         print "instances of sage and use 'sage -i' instead or"
    122         print "use the force option to install_package."
     140        print "instances of Sage and use 'sage -i %s' instead or" % package
     141        print "use the force option to install_package()."
    123142
    124143    if package is None:
    125144        if __installed_packages is None:
    126             X = os.popen('sage -f').read().split('\n')
    127             i = X.index('Currently installed packages:')
    128             X = [Y for Y in X[i+1:] if Y != '']
    129             X.sort()
    130             __installed_packages = X
     145            __installed_packages = sorted(os.listdir(
     146                os.path.join(os.environ["SAGE_PACKAGES"], 'installed')))
    131147        return __installed_packages
    132     # Get full package name
     148    # Get full package name / list of candidates:
    133149    if force:
     150        # Also search packages already installed.
    134151        S = [P for P in standard_packages()[0] if P.startswith(package)]
    135152        O = [P for P in optional_packages()[0] if P.startswith(package)]
    136153        E = [P for P in experimental_packages()[0] if P.startswith(package)]
     
    153170            if is_package_installed(package):
    154171                raise ValueError, "Package is already installed. Try install_package('%s',force=True)"%(package)
    155172        raise ValueError, "There is no package name starting with '%s'."%(package)
     173    # len(L)==1, i.e. exactly one package matches the given one.
    156174    os.system('sage -f "%s"'%(L[0]))
    157175    __installed_packages = None
    158176
     
    195213        j = X.index('NOT INSTALLED:')
    196214    except ValueError, msg:
    197215        print R
    198         print "standard package list (shown above) appears to be currently not available or corrupted (network error?)."
     216        print "Standard package list (shown above) appears to be currently"
     217        print "not available or corrupted (network error?)."
    199218        return [], []
    200219   
    201220    installed = []