Skip to content

Commit 61eccb0

Browse files
author
Release Manager
committed
sagemathgh-39796: fix: added check for FriCAS version This pull request includes several updates to the `FriCAS` class in the `src/sage/features/fricas.py` file. The changes introduce a minimum version requirement, add a method to retrieve the installed FriCAS version, and enhance the `is_functional` method to check the version.This is an attempt to fix the issue [39784](sagemath#39784) Enhancements to version handling and functionality checks: * [`src/sage/features/fricas.py`](diffhunk://#diff- a2c0d819d857ba2338e0d58e1a4875c88b600b174c8fb4371183ecc3f0e5b72eR29- R30): Added a `MINIMUM_VERSION` attribute to specify the minimum required version of FriCAS. * [`src/sage/features/fricas.py`](diffhunk://#diff- a2c0d819d857ba2338e0d58e1a4875c88b600b174c8fb4371183ecc3f0e5b72eR43- R54): Introduced a `get_version` method to retrieve the installed FriCAS version. * [`src/sage/features/fricas.py`](diffhunk://#diff- a2c0d819d857ba2338e0d58e1a4875c88b600b174c8fb4371183ecc3f0e5b72eL61- R85): Updated the `is_functional` method to call `get_version` and check if the installed version meets the minimum requirement. If the version is not retrievable or is too old, appropriate error messages are returned. <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39796 Reported by: Devansh Srivastava Reviewer(s): Dima Pasechnik
2 parents 907342d + 9897efb commit 61eccb0

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

Diff for: src/sage/features/fricas.py

+33-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import subprocess
1616
from . import Executable, FeatureTestResult
17+
from packaging.version import Version
1718

1819

1920
class FriCAS(Executable):
@@ -26,6 +27,8 @@ class FriCAS(Executable):
2627
sage: FriCAS().is_present() # optional - fricas
2728
FeatureTestResult('fricas', True)
2829
"""
30+
MINIMUM_VERSION = "1.3.8"
31+
2932
def __init__(self):
3033
r"""
3134
TESTS::
@@ -38,6 +41,23 @@ def __init__(self):
3841
executable='fricas',
3942
url='https://fricas.github.io')
4043

44+
def get_version(self):
45+
r"""
46+
Retrieve the installed FriCAS version
47+
48+
EXAMPLES::
49+
sage: from sage.features.fricas import FriCAS
50+
sage: FriCAS().get_version() # optional - fricas
51+
'1.3...'
52+
"""
53+
try:
54+
output = subprocess.check_output(['fricas', '--version'], stderr=subprocess.STDOUT)
55+
version_line = output.decode('utf-8').strip()
56+
version = version_line.split()[1]
57+
return version
58+
except subprocess.CalledProcessError:
59+
return None
60+
4161
def is_functional(self):
4262
r"""
4363
Check whether ``fricas`` works on trivial input.
@@ -53,14 +73,24 @@ def is_functional(self):
5373
lines = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)
5474
except subprocess.CalledProcessError as e:
5575
return FeatureTestResult(self, False,
56-
reason="Call `{command}` failed with exit code {e.returncode}".format(command=" ".join(command), e=e))
76+
reason="Call `{command}` failed with exit code {e.returncode}".format(command=" ".join(command), e=e))
5777

5878
expected = b"FriCAS"
5979
if lines.find(expected) == -1:
6080
return FeatureTestResult(self, False,
61-
reason="Call `{command}` did not produce output which contains `{expected}`".format(command=" ".join(command), expected=expected))
81+
reason="Call `{command}` did not produce output which contains `{expected}`".format(command=" ".join(command),
82+
expected=expected))
83+
version = self.get_version()
84+
if version is None:
85+
return FeatureTestResult(self, False,
86+
reason="Could not determine FriCAS version")
6287

63-
return FeatureTestResult(self, True)
88+
try:
89+
if Version(version) < Version(self.MINIMUM_VERSION):
90+
return FeatureTestResult(self, False, reason=f"FriCAS version {version} is too old; minimum required is {self.MINIMUM_VERSION}")
91+
return FeatureTestResult(self, True)
92+
except ValueError:
93+
return FeatureTestResult(self, False, reason="Invalid Version Format")
6494

6595

6696
def all_features():

0 commit comments

Comments
 (0)