This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/sage/features/interfaces.py: New
- Loading branch information
Matthias Koeppe
committed
Nov 13, 2021
1 parent
6ec717a
commit eaec400
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
r""" | ||
Check for working interpreter interfaces | ||
""" | ||
import importlib | ||
|
||
from . import Feature, FeatureTestResult, PythonModule | ||
|
||
|
||
class InterfaceFeature(Feature): | ||
|
||
@staticmethod | ||
def __classcall__(cls, name, module, description=None): | ||
if isinstance(module, str): | ||
module = PythonModule(module) | ||
return Feature.__classcall__(cls, name, module, description) | ||
|
||
def __init__(self, name, module, description): | ||
super().__init__(name, description=description) | ||
self.module = module | ||
|
||
def _is_present(self): | ||
result = self.module.is_present() | ||
if not result: | ||
return result | ||
m = importlib.import_module(self.module.name) | ||
try: | ||
interface = getattr(m, self.name) | ||
interface('2+3') | ||
return FeatureTestResult(self, True) | ||
except Exception as exception: | ||
return FeatureTestResult(self, False, | ||
reason=f"Interface {interface} is not functional: {exception}") | ||
|
||
# The following are provided by external software only (no SPKG) | ||
|
||
class Magma(InterfaceFeature): | ||
r""" | ||
A :class:`sage.features.Feature` describing whether :class:`sage.interfaces.magma.Magma` | ||
is present and functional. | ||
EXAMPLES:: | ||
sage: from sage.features.interfaces import Magma | ||
sage: Magma().is_present() # random | ||
FeatureTestResult('jupymake', False) | ||
""" | ||
|
||
@staticmethod | ||
def __classcall__(cls): | ||
return InterfaceFeature(cls, 'magma', 'sage.interfaces.magma') | ||
|
||
|
||
class Matlab(InterfaceFeature): | ||
|
||
@staticmethod | ||
def __classcall__(cls): | ||
return InterfaceFeature(cls, 'matlab', 'sage.interfaces.matlab') | ||
|
||
|
||
class Mathematica(InterfaceFeature): | ||
|
||
@staticmethod | ||
def __classcall__(cls): | ||
return InterfaceFeature(cls, 'mathematica', 'sage.interfaces.mathematica') | ||
|
||
|
||
class Maple(InterfaceFeature): | ||
|
||
@staticmethod | ||
def __classcall__(cls): | ||
return InterfaceFeature(cls, 'maple', 'sage.interfaces.maple') | ||
|
||
|
||
class Macaulay2(InterfaceFeature): | ||
|
||
@staticmethod | ||
def __classcall__(cls): | ||
return InterfaceFeature(cls, 'macaulay2', 'sage.interfaces.macaulay2') | ||
|
||
|
||
class Octave(InterfaceFeature): | ||
|
||
@staticmethod | ||
def __classcall__(cls): | ||
return InterfaceFeature(cls, 'octave', 'sage.interfaces.octave') | ||
|
||
|
||
class Scilab(InterfaceFeature): | ||
|
||
@staticmethod | ||
def __classcall__(cls): | ||
return InterfaceFeature(cls, 'scilab', 'sage.interfaces.scilab') |