Skip to content

Commit

Permalink
Trac #33167: Improve is_functional of lrs feature
Browse files Browse the repository at this point in the history
From https://trac.sagemath.org/ticket/33101#comment:3 :

"''This was after a distclean. I had not explicitly installed lrslib, it
was on the system. If I understand the config.log correctly, the system
lrslib was not accepted by Sage. Yet, ptestlong runs the optional lrslib
tests.''"

{{{
## ------------------------------------------------------- ##
## Checking whether SageMath should install SPKG lrslib... ##
## ------------------------------------------------------- ##
configure:30190: checking whether any of gmp flint is installed as or
will be installed as SPKG
configure:30194: result: yes; install lrslib as well
configure:30296: no suitable system package found for SPKG lrslib
}}}

----

In this ticket, we add to the `is_functional` method a check
corresponding to the check made in `build/pkgs/lrslib/spkg-configure.m4`
so that if `lrslib` is not picked up by sagemath at configuration/build
time, then it is not picked up by sagemath at runtime or during
doctests.

URL: https://trac.sagemath.org/33167
Reported by: slabbe
Ticket author(s): Sébastien Labbé, Markus Wageringel
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Feb 13, 2022
2 parents ab3995f + 16e1b24 commit 14f11b0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
3 changes: 3 additions & 0 deletions build/pkgs/lrslib/spkg-configure.m4
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
SAGE_SPKG_CONFIGURE([lrslib], [
dnl Although lrs and lrsnash binaries are the only interfaces to lrslib that
dnl sagelib uses, the optional polymake package uses lrslib as a library, so
dnl the following DEPCHECK is needed.
dnl System lrslib may already be 7.x, which may be compiled with FLINT
SAGE_SPKG_DEPCHECK([gmp flint], [
AC_CHECK_PROGS([LRSNASH], [lrsnash])
Expand Down
47 changes: 35 additions & 12 deletions src/sage/features/lrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
Feature for testing the presence of ``lrslib``
"""

import os
import subprocess

from . import Executable, FeatureTestResult
from sage.cpython.string import str_to_bytes, bytes_to_str


class Lrs(Executable):
Expand Down Expand Up @@ -43,24 +41,49 @@ def is_functional(self):
FeatureTestResult('lrslib', True)
"""
from sage.misc.temporary_file import tmp_filename

# Check #1
tf_name = tmp_filename()
with open(tf_name, 'wb') as tf:
tf.write(str_to_bytes("V-representation\nbegin\n 1 1 rational\n 1 \nend\nvolume"))
devnull = open(os.devnull, 'wb')
with open(tf_name, 'w') as tf:
tf.write("V-representation\nbegin\n 1 1 rational\n 1 \nend\nvolume")
command = ['lrs', tf_name]
try:
lines = bytes_to_str(subprocess.check_output(command, stderr=devnull))
except subprocess.CalledProcessError as e:
result = subprocess.run(command, capture_output=True, text=True)
except OSError as e:
return FeatureTestResult(self, False, reason='Running command "{}" '
'raised an OSError "{}" '.format(' '.join(command), e))

if result.returncode:
return FeatureTestResult(self, False,
reason="Call to `{command}` failed with exit code {e.returncode}.".format(command=" ".join(command), e=e))
reason="Call to `{command}` failed with exit code {result.returncode}.".format(command=" ".join(command), result=result))

expected_list = ["Volume= 1", "Volume=1"]
if all(lines.find(expected) == -1 for expected in expected_list):
print(lines)
if all(result.stdout.find(expected) == -1 for expected in expected_list):
return FeatureTestResult(self, False,
reason="Output of `{command}` did not contain the expected result {expected}.".format(
reason="Output of `{command}` did not contain the expected result {expected}; output: {result.stdout}".format(
command=" ".join(command),
expected=" or ".join(expected_list)))
expected=" or ".join(expected_list),
result=result))

# Check #2
# Checking whether `lrsnash` can handle the new input format
# This test is currently done in build/pkgs/lrslib/spkg-configure.m4
tf_name = tmp_filename()
with open(tf_name, 'w') as tf:
tf.write("1 1\n \n 0\n \n 0\n")
command = ['lrsnash', tf_name]
try:
result = subprocess.run(command, capture_output=True, text=True)
except OSError as e:
return FeatureTestResult(self, False, reason='Running command "{}" '
'raised an OSError "{}" '.format(' '.join(command), e))
if result.returncode:
return FeatureTestResult(self, False, reason='Running command "{}" '
'returned non-zero exit status "{}" with stderr '
'"{}" and stdout "{}".'.format(' '.join(result.args),
result.returncode,
result.stderr.strip(),
result.stdout.strip()))

return FeatureTestResult(self, True)

Expand Down

0 comments on commit 14f11b0

Please sign in to comment.