-
-
Notifications
You must be signed in to change notification settings - Fork 404
/
gap.py
86 lines (70 loc) · 3.24 KB
/
gap.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
# sage_setup: distribution = sagemath-environment
r"""
Features for testing the presence of the SageMath interfaces to ``gap`` and of GAP packages
"""
# *****************************************************************************
# Copyright (C) 2016 Julian Rüth
# 2018 Jeroen Demeyer
#
# 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/
# *****************************************************************************
from . import Feature, FeatureTestResult, PythonModule
from .join_feature import JoinFeature
from .sagemath import sage__libs__gap
class GapPackage(Feature):
r"""
A :class:`~sage.features.Feature` describing the presence of a GAP package.
A GAP package is "present" if it *can be* loaded, not if it *has
been* loaded.
.. SEEALSO::
:class:`Feature sage.libs.gap <~sage.features.sagemath.sage__libs__gap>`
EXAMPLES::
sage: from sage.features.gap import GapPackage
sage: GapPackage("grape", spkg="gap_packages")
Feature('gap_package_grape')
"""
def __init__(self, package, **kwds):
r"""
TESTS::
sage: from sage.features.gap import GapPackage
sage: isinstance(GapPackage("grape", spkg="gap_packages"), GapPackage)
True
"""
Feature.__init__(self, f"gap_package_{package}", **kwds)
self.package = package
def _is_present(self):
r"""
Return whether or not the GAP package is present.
If the package is installed but not yet loaded, it is loaded
first. This does *not* check that the package is functional.
EXAMPLES::
sage: from sage.features.gap import GapPackage
sage: GapPackage("grape", spkg="gap_packages")._is_present() # optional - gap_package_grape
FeatureTestResult('gap_package_grape', True)
"""
try:
from sage.libs.gap.libgap import libgap
except ImportError:
return FeatureTestResult(self, False,
reason="sage.libs.gap is not available")
# This returns "true" even if the package is already loaded.
command = 'LoadPackage("{package}")'.format(package=self.package)
presence = libgap.eval(command)
if presence:
return FeatureTestResult(self, True,
reason="`{command}` evaluated to `{presence}` in GAP.".format(command=command, presence=presence))
else:
return FeatureTestResult(self, False,
reason="`{command}` evaluated to `{presence}` in GAP.".format(command=command, presence=presence))
def all_features():
return [GapPackage("atlasrep", spkg="gap_packages"),
GapPackage("design", spkg="gap_packages"),
GapPackage("grape", spkg="gap_packages"),
GapPackage("guava", spkg="gap_packages"),
GapPackage("hap", spkg="gap_packages"),
GapPackage("polycyclic", spkg="gap_packages"),
GapPackage("qpa", spkg="gap_packages"),
GapPackage("quagroup", spkg="gap_packages")]