-
-
Notifications
You must be signed in to change notification settings - Fork 404
/
lrs.py
164 lines (132 loc) · 5.82 KB
/
lrs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# sage_setup: distribution = sagemath-environment
r"""
Feature for testing the presence of ``lrslib``
"""
# *****************************************************************************
# Copyright (C) 2016 Julian Rüth
# 2018 Jeroen Demeyer
# 2021-2022 Matthias Koeppe
# 2021 Kwankyu Lee
# 2022 Sébastien Labbé
#
# 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 subprocess
from . import Executable, FeatureTestResult
from .join_feature import JoinFeature
class Lrs(Executable):
r"""
A :class:`~sage.features.Feature` describing the presence of the ``lrs``
binary which comes as a part of ``lrslib``.
EXAMPLES::
sage: from sage.features.lrs import Lrs
sage: Lrs().is_present() # optional - lrslib
FeatureTestResult('lrs', True)
"""
def __init__(self):
r"""
TESTS::
sage: from sage.features.lrs import Lrs
sage: isinstance(Lrs(), Lrs)
True
"""
Executable.__init__(self, "lrs", executable="lrs", spkg="lrslib",
url="http://cgm.cs.mcgill.ca/~avis/C/lrs.html")
def is_functional(self):
r"""
Test whether ``lrs`` works on a trivial input.
EXAMPLES::
sage: from sage.features.lrs import Lrs
sage: Lrs().is_functional() # optional - lrslib
FeatureTestResult('lrs', True)
"""
from sage.misc.temporary_file import tmp_filename
tf_name = tmp_filename()
with open(tf_name, 'w') as tf:
tf.write("V-representation\nbegin\n 1 1 rational\n 1 \nend\nvolume")
command = [self.absolute_filename(), 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="Call to `{command}` failed with exit code {result.returncode}.".format(command=" ".join(command), result=result))
expected_list = ["Volume= 1", "Volume=1"]
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}; output: {result.stdout}".format(
command=" ".join(command),
expected=" or ".join(expected_list),
result=result))
return FeatureTestResult(self, True)
class LrsNash(Executable):
r"""
A :class:`~sage.features.Feature` describing the presence of the ``lrsnash``
binary which comes as a part of ``lrslib``.
EXAMPLES::
sage: from sage.features.lrs import LrsNash
sage: LrsNash().is_present() # optional - lrslib
FeatureTestResult('lrsnash', True)
"""
def __init__(self):
r"""
TESTS::
sage: from sage.features.lrs import LrsNash
sage: isinstance(LrsNash(), LrsNash)
True
"""
Executable.__init__(self, "lrsnash", executable="lrsnash", spkg="lrslib",
url="http://cgm.cs.mcgill.ca/~avis/C/lrs.html")
def is_functional(self):
r"""
Test whether ``lrsnash`` works on a trivial input.
EXAMPLES::
sage: from sage.features.lrs import LrsNash
sage: LrsNash().is_functional() # optional - lrslib
FeatureTestResult('lrsnash', True)
"""
from sage.misc.temporary_file import tmp_filename
# 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 = [self.absolute_filename(), 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)
class Lrslib(JoinFeature):
r"""
A :class:`~sage.features.Feature` describing the presence of the executables
:class:`lrs <Lrs>` and :class:`lrsnash <LrsNash>` provided by the :ref:`lrslib <spkg_lrslib>` package.
EXAMPLES::
sage: from sage.features.lrs import Lrslib
sage: Lrslib().is_present() # optional - lrslib
FeatureTestResult('lrslib', True)
"""
def __init__(self):
r"""
TESTS::
sage: from sage.features.lrs import Lrslib
sage: isinstance(Lrslib(), Lrslib)
True
"""
JoinFeature.__init__(self, "lrslib",
(Lrs(), LrsNash()))
def all_features():
return [Lrslib()]