Skip to content

Commit 47073ef

Browse files
committed
updated design of feature
1 parent 0d7aebe commit 47073ef

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

src/sage/features/fricas.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
r"""
2+
Features for testing the presence of ``fricas``
3+
"""
4+
5+
# *****************************************************************************
6+
# Copyright (C) 2023 Dima Pasechnik
7+
#
8+
# Distributed under the terms of the GNU General Public License (GPL)
9+
# as published by the Free Software Foundation; either version 2 of
10+
# the License, or (at your option) any later version.
11+
# https://www.gnu.org/licenses/
12+
# *****************************************************************************
13+
14+
import os
15+
import subprocess
16+
from . import Executable, FeatureTestResult
17+
18+
class FriCAS(Executable):
19+
r"""
20+
A :class:`~sage.features.Feature` which checks for the :ref:`fricas <fricas>` binary.
21+
22+
EXAMPLES::
23+
24+
sage: from sage.features.fricas import FriCAS
25+
sage: FriCAS().is_present() # optional - fricas
26+
FeatureTestResult('fricas', True)
27+
"""
28+
def __init__(self):
29+
r"""
30+
TESTS::
31+
32+
sage: from sage.features.fricas import FriCAS
33+
sage: isinstance(FriCAS(), FriCAS)
34+
True
35+
"""
36+
Executable.__init__(self, name="fricas", spkg="fricas",
37+
executable="fricas",
38+
url="https://fricas.github.io")
39+
40+
def is_functional(self):
41+
r"""
42+
Check whether ``fricas`` works on trivial input.
43+
44+
EXAMPLES::
45+
46+
sage: from sage.features.fricas import FriCAS
47+
sage: FriCAS().is_functional() # optional - fricas
48+
FeatureTestResult('fricas', True)
49+
"""
50+
command = ["fricas -nosman", "2+2"]
51+
try:
52+
lines = subprocess.check_output(command, stderr=subprocess.STDOUT)
53+
except subprocess.CalledProcessError as e:
54+
return FeatureTestResult(self, False,
55+
reason="Call `{command}` failed with exit code {e.returncode}".format(command=" ".join(command), e=e))
56+
57+
expected = b"4"
58+
if lines.find(expected) == -1:
59+
return FeatureTestResult(self, False,
60+
reason="Call `{command}` did not produce output which contains `{expected}`".format(command=" ".join(command), expected=expected))
61+
62+
return FeatureTestResult(self, True)
63+
64+
def all_features():
65+
return [FriCAS()]

src/sage/interfaces/fricas.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ 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,
269-
server=None, server_tmpdir=None):
269+
server=None, server_tmpdir=None, options="-nosman"):
270270
"""
271271
Create an instance of the FriCAS interpreter.
272272
@@ -289,6 +289,13 @@ def __init__(self, name='fricas', command='fricas -nosman',
289289
sage: fricas(I*x).sage() # optional - fricas
290290
I*x
291291
"""
292+
from sage.features.fricas import FriCAS
293+
FriCAS().require()
294+
295+
import shlex
296+
command = '{} {}'.format(shlex.quote(FriCAS().absolute_filename()),
297+
options)
298+
292299
eval_using_file_cutoff = 4096 - 5 # magic number from Expect._eval_line (there might be a bug)
293300
assert max(len(c) for c in FRICAS_INIT_CODE) < eval_using_file_cutoff
294301
self.__eval_using_file_cutoff = eval_using_file_cutoff

0 commit comments

Comments
 (0)