Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Detecting external software
This module makes up a list of external software that Sage interfaces. Availability of each software is tested only when necessary. This is mainly used for the doctests which require certain external software installed on the system.
AUTHORS:
- Kwankyu Lee (2016-03-09) -- initial version, based on code by Robert Bradshaw and Nathann Cohen """
#***************************************************************************** # Copyright (C) 2016 KWANKYU LEE <ekwankyu@gmail.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #*****************************************************************************
from multiprocessing import Array
# Functions in this module whose name is of the form 'has_xxx' tests if the # software xxx is available to Sage. prefix = 'has_'
def has_internet(): """ Test if Internet is available.
Failure of connecting to the site "http://www.sagemath.org" within a second is regarded as internet being not available.
EXAMPLES::
sage: from sage.doctest.external import has_internet sage: has_internet() # random True """ return True
def has_latex(): """ Test if Latex is available.
EXAMPLES::
sage: from sage.doctest.external import has_latex sage: has_latex() # random True """ except Exception: return False
def has_magma(): """ Test if Magma is available.
EXAMPLES::
sage: from sage.doctest.external import has_magma sage: has_magma() # random True """ return True
def has_matlab(): """ Test if Matlab is available.
EXAMPLES::
sage: from sage.doctest.external import has_matlab sage: has_matlab() # random True """ return True
def has_mathematica(): """ Test if Mathematica is available.
EXAMPLES::
sage: from sage.doctest.external import has_mathematica sage: has_mathematica() # random True """ return True
def has_maple(): """ Test if Maple is available.
EXAMPLES::
sage: from sage.doctest.external import has_maple sage: has_maple() # random True """ return True
def has_macaulay2(): """ Test if Macaulay2 is available.
EXAMPLES::
sage: from sage.doctest.external import has_macaulay2 sage: has_macaulay2() # random True """ return True
def has_octave(): """ Test if Octave is available.
EXAMPLES::
sage: from sage.doctest.external import has_octave sage: has_octave() # random True """ return True
def has_scilab(): """ Test if Scilab is available.
EXAMPLES::
sage: from sage.doctest.external import has_scilab sage: has_scilab() # random True """ return True
def has_cplex(): """ Test if CPLEX is available.
EXAMPLES::
sage: from sage.doctest.external import has_cplex sage: has_cplex() # random True """ return True
def has_gurobi(): """ Test if Gurobi is available.
EXAMPLES::
sage: from sage.doctest.external import has_gurobi sage: has_gurobi() # random True """ return True
def external_software(): """ Return the alphabetical list of external software supported by this module.
EXAMPLES::
sage: from sage.doctest.external import external_software sage: sorted(external_software) == external_software True """ supported = list() for func in globals(): if func.startswith(prefix): supported.append(func[len(prefix):]) return sorted(supported)
external_software = external_software()
def _lookup(software): """ Test if the software is available on the system.
EXAMPLES::
sage: sage.doctest.external._lookup('internet') # random True """ else: return False
class AvailableSoftware(object): """ This class keeps the set of available software whose availability is detected lazily from the list of external software.
EXAMPLES::
sage: from sage.doctest.external import external_software, available_software sage: external_software ['cplex', 'gurobi', 'internet', 'latex', 'macaulay2', 'magma', 'maple', 'mathematica', 'matlab', 'octave', 'scilab'] sage: 'internet' in available_software # random True sage: available_software.issuperset(set(['internet','latex'])) # random True """ def __init__(self): """ Initialization.
EXAMPLES::
sage: from sage.doctest.external import AvailableSoftware sage: S = AvailableSoftware() sage: S.seen() # random [] """ # For multiprocessing of doctests, the data self._seen should be # shared among subprocesses. Thus we use Array class from the # multiprocessing module.
def __contains__(self, item): """ Return ``True`` if ``item`` is available on the system.
EXAMPLES::
sage: from sage.doctest.external import available_software sage: 'internet' in available_software # random True """ except Exception: return False else: else: raise AssertionError("Invalid value for self.seen")
def issuperset(self, other): """ Return ``True`` if ``other`` is a subset of ``self``.
EXAMPLES::
sage: from sage.doctest.external import available_software sage: available_software.issuperset(set(['internet','latex','magma'])) # random True """ return True
def seen(self): """ Return the list of detected external software.
EXAMPLES::
sage: from sage.doctest.external import available_software sage: available_software.seen() # random ['internet', 'latex', 'magma'] """
available_software = AvailableSoftware() |