Skip to content

Commit

Permalink
updated design of feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dimpase committed Jul 1, 2023
1 parent 0d7aebe commit 47073ef
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
65 changes: 65 additions & 0 deletions src/sage/features/fricas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
r"""
Features for testing the presence of ``fricas``
"""

# *****************************************************************************
# Copyright (C) 2023 Dima Pasechnik
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# https://www.gnu.org/licenses/
# *****************************************************************************

import os
import subprocess
from . import Executable, FeatureTestResult

class FriCAS(Executable):
r"""
A :class:`~sage.features.Feature` which checks for the :ref:`fricas <fricas>` binary.
EXAMPLES::
sage: from sage.features.fricas import FriCAS
sage: FriCAS().is_present() # optional - fricas
FeatureTestResult('fricas', True)
"""
def __init__(self):
r"""
TESTS::
sage: from sage.features.fricas import FriCAS
sage: isinstance(FriCAS(), FriCAS)
True
"""
Executable.__init__(self, name="fricas", spkg="fricas",
executable="fricas",
url="https://fricas.github.io")

def is_functional(self):
r"""
Check whether ``fricas`` works on trivial input.
EXAMPLES::
sage: from sage.features.fricas import FriCAS
sage: FriCAS().is_functional() # optional - fricas
FeatureTestResult('fricas', True)
"""
command = ["fricas -nosman", "2+2"]
try:
lines = subprocess.check_output(command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
return FeatureTestResult(self, False,
reason="Call `{command}` failed with exit code {e.returncode}".format(command=" ".join(command), e=e))

expected = b"4"
if lines.find(expected) == -1:
return FeatureTestResult(self, False,
reason="Call `{command}` did not produce output which contains `{expected}`".format(command=" ".join(command), expected=expected))

return FeatureTestResult(self, True)

def all_features():
return [FriCAS()]
11 changes: 9 additions & 2 deletions src/sage/interfaces/fricas.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ class FriCAS(ExtraTabCompletion, Expect):
"""
Interface to a FriCAS interpreter.
"""
def __init__(self, name='fricas', command='fricas -nosman',
def __init__(self, name='fricas', command=None,
script_subdirectory=None, logfile=None,
server=None, server_tmpdir=None):
server=None, server_tmpdir=None, options="-nosman"):
"""
Create an instance of the FriCAS interpreter.
Expand All @@ -289,6 +289,13 @@ def __init__(self, name='fricas', command='fricas -nosman',
sage: fricas(I*x).sage() # optional - fricas
I*x
"""
from sage.features.fricas import FriCAS
FriCAS().require()

import shlex
command = '{} {}'.format(shlex.quote(FriCAS().absolute_filename()),
options)

eval_using_file_cutoff = 4096 - 5 # magic number from Expect._eval_line (there might be a bug)
assert max(len(c) for c in FRICAS_INIT_CODE) < eval_using_file_cutoff
self.__eval_using_file_cutoff = eval_using_file_cutoff
Expand Down

0 comments on commit 47073ef

Please sign in to comment.