Skip to content

Commit 38d728e

Browse files
Matthias Koeppedimpase
Matthias Koeppe
authored andcommitted
implement sage's feature for FriCAS
This is taken from #33575
1 parent 0d7aebe commit 38d728e

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

src/sage/features/interfaces.py

+41-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import importlib
1616

17-
from . import Feature, FeatureTestResult, PythonModule
17+
from . import Executable, Feature, FeatureTestResult, PythonModule
1818

1919

2020
class InterfaceFeature(Feature):
@@ -37,7 +37,7 @@ class InterfaceFeature(Feature):
3737
"Interface also_broken_interface cannot be imported: module 'sage.interfaces.interface' has no attribute 'also_broken_interface'"
3838
"""
3939
@staticmethod
40-
def __classcall__(cls, name, module, description=None):
40+
def __classcall__(cls, name, module, description=None, **kwds):
4141
"""
4242
TESTS::
4343
@@ -49,9 +49,9 @@ def __classcall__(cls, name, module, description=None):
4949
"""
5050
if isinstance(module, str):
5151
module = PythonModule(module)
52-
return Feature.__classcall__(cls, name, module, description)
52+
return Feature.__classcall__(cls, name, module, description, **kwds)
5353

54-
def __init__(self, name, module, description):
54+
def __init__(self, name, module, description, **kwds):
5555
"""
5656
TESTS::
5757
@@ -60,7 +60,7 @@ def __init__(self, name, module, description):
6060
sage: isinstance(f, InterfaceFeature)
6161
True
6262
"""
63-
super().__init__(name, description=description)
63+
super().__init__(name, description=description, **kwds)
6464
self.module = module
6565

6666
def _is_present(self):
@@ -90,6 +90,38 @@ def _is_present(self):
9090
reason=f"Interface {interface} is not functional: {exception}")
9191

9292

93+
class FriCASExecutable(Executable):
94+
r"""
95+
A :class:`~sage.features.Feature` describing whether :class:`sage.interfaces.fricas.FriCAS`
96+
is present and functional.
97+
98+
EXAMPLES::
99+
100+
sage: from sage.features.interfaces import FriCASExecutable
101+
sage: FriCASExecutable().is_present() # random
102+
FeatureTestResult('fricas_exe', False)
103+
"""
104+
@staticmethod
105+
def __classcall__(cls):
106+
return Executable.__classcall__(cls, 'fricas_exe', 'fricas', spkg='fricas')
107+
108+
109+
class FriCAS(InterfaceFeature):
110+
r"""
111+
A :class:`~sage.features.Feature` describing whether :class:`sage.interfaces.fricas.FriCAS`
112+
is present and functional.
113+
114+
EXAMPLES::
115+
116+
sage: from sage.features.interfaces import FriCAS
117+
sage: FriCAS().is_present() # random
118+
FeatureTestResult('fricas', False)
119+
"""
120+
@staticmethod
121+
def __classcall__(cls):
122+
return InterfaceFeature.__classcall__(cls, 'fricas', 'sage.interfaces.fricas', spkg='fricas')
123+
124+
93125
# The following are provided by external software only (no SPKG)
94126

95127
class Magma(InterfaceFeature):
@@ -219,15 +251,17 @@ def all_features():
219251
220252
sage: from sage.features.interfaces import all_features
221253
sage: list(all_features())
222-
[Feature('magma'),
254+
[Feature('fricas'),
255+
Feature('magma'),
223256
Feature('matlab'),
224257
Feature('mathematica'),
225258
Feature('maple'),
226259
Feature('macaulay2'),
227260
Feature('octave'),
228261
Feature('scilab')]
229262
"""
230-
return [Magma(),
263+
return [FriCAS(),
264+
Magma(),
231265
Matlab(),
232266
Mathematica(),
233267
Maple(),

src/sage/interfaces/fricas.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class FriCAS(ExtraTabCompletion, Expect):
264264
"""
265265
Interface to a FriCAS interpreter.
266266
"""
267-
def __init__(self, name='fricas', command='fricas -nosman',
267+
def __init__(self, name='fricas', command=None,
268268
script_subdirectory=None, logfile=None,
269269
server=None, server_tmpdir=None):
270270
"""
@@ -289,6 +289,10 @@ def __init__(self, name='fricas', command='fricas -nosman',
289289
sage: fricas(I*x).sage() # optional - fricas
290290
I*x
291291
"""
292+
if command is None:
293+
from sage.features.interfaces import FriCASExecutable
294+
fricas_exe = FriCASExecutable().absolute_filename()
295+
command = f'{fricas_exe} -nosman'
292296
eval_using_file_cutoff = 4096 - 5 # magic number from Expect._eval_line (there might be a bug)
293297
assert max(len(c) for c in FRICAS_INIT_CODE) < eval_using_file_cutoff
294298
self.__eval_using_file_cutoff = eval_using_file_cutoff

0 commit comments

Comments
 (0)