|
| 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()] |
0 commit comments