diff --git a/build/pkgs/lrslib/spkg-configure.m4 b/build/pkgs/lrslib/spkg-configure.m4 index 0297f7118e3..752dcfe8fbf 100644 --- a/build/pkgs/lrslib/spkg-configure.m4 +++ b/build/pkgs/lrslib/spkg-configure.m4 @@ -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]) diff --git a/src/sage/features/lrs.py b/src/sage/features/lrs.py index 4defebd069f..f6a4d922bd0 100644 --- a/src/sage/features/lrs.py +++ b/src/sage/features/lrs.py @@ -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): @@ -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)