Skip to content

Commit c706cf8

Browse files
author
Release Manager
committed
gh-38180: `sage.interfaces`: More `lazy_import` <!-- ^ 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 #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 #12345". --> This includes some updates for low-level doctests so that they do not trip over `LazyImport` objects. - Cherry-picked from #35095 / #36380 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #38180 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
2 parents 82fda3e + d95cc88 commit c706cf8

File tree

10 files changed

+30
-15
lines changed

10 files changed

+30
-15
lines changed

src/sage/categories/pushout.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,14 +3976,20 @@ class BlackBoxConstructionFunctor(ConstructionFunctor):
39763976
EXAMPLES::
39773977
39783978
sage: from sage.categories.pushout import BlackBoxConstructionFunctor
3979+
3980+
sage: # needs sage.libs.gap
3981+
sage: from sage.interfaces.gap import gap
39793982
sage: FG = BlackBoxConstructionFunctor(gap)
3980-
sage: FS = BlackBoxConstructionFunctor(singular)
39813983
sage: FG
39823984
BlackBoxConstructionFunctor
3983-
sage: FG(ZZ) # needs sage.libs.gap
3985+
sage: FG(ZZ)
39843986
Integers
3985-
sage: FG(ZZ).parent() # needs sage.libs.gap
3987+
sage: FG(ZZ).parent()
39863988
Gap
3989+
sage: FG == loads(dumps(FG))
3990+
True
3991+
3992+
sage: FS = BlackBoxConstructionFunctor(singular)
39873993
sage: FS(QQ['t']) # needs sage.libs.singular
39883994
polynomial ring, over a field, global ordering
39893995
// coefficients: QQ
@@ -3993,8 +3999,6 @@ class BlackBoxConstructionFunctor(ConstructionFunctor):
39933999
// block 2 : ordering C
39944000
sage: FG == FS # needs sage.libs.gap sage.libs.singular
39954001
False
3996-
sage: FG == loads(dumps(FG)) # needs sage.libs.gap
3997-
True
39984002
"""
39994003
rank = 100
40004004

src/sage/doctest/forker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,7 @@ def report_unexpected_exception(self, out, test, example, exc_info):
15791579
15801580
EXAMPLES::
15811581
1582+
sage: from sage.interfaces.sage0 import sage0
15821583
sage: sage0.quit()
15831584
sage: _ = sage0.eval("import doctest, sys, os, multiprocessing, subprocess")
15841585
sage: _ = sage0.eval("from sage.doctest.parsing import SageOutputChecker")

src/sage/interfaces/all.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
# interfaces to other interpreters
22

3-
from sage.interfaces.sage0 import sage0, sage0_version, Sage
4-
from sage.interfaces.gap import gap, gap_reset_workspace, Gap
5-
from sage.interfaces.gp import gp, gp_version, Gp
63
# import problems
7-
# from maxima_lib import maxima_lib
8-
from sage.interfaces.maxima import maxima, Maxima
9-
from sage.interfaces.singular import singular, singular_version, Singular
10-
11-
from sage.interfaces.magma import magma, Magma
12-
from sage.interfaces.polymake import polymake
4+
try:
5+
# from maxima_lib import maxima_lib
6+
from sage.interfaces.maxima import maxima, Maxima
7+
except ImportError:
8+
pass
139

1410
from sage.misc.lazy_import import lazy_import
1511

12+
lazy_import('sage.interfaces.sage0', ['sage0', 'sage0_version', 'Sage'])
1613
lazy_import('sage.interfaces.axiom', ['Axiom', 'axiom'])
1714
lazy_import('sage.interfaces.ecm', ['ECM', 'ecm'])
1815
lazy_import('sage.interfaces.four_ti_2', 'four_ti_2')
1916
lazy_import('sage.interfaces.fricas', ['FriCAS', 'fricas'])
2017
lazy_import('sage.interfaces.frobby', 'frobby')
18+
lazy_import('sage.interfaces.gap', ['gap', 'gap_reset_workspace', 'Gap'])
2119
lazy_import('sage.interfaces.gap3', ['gap3', 'gap3_version', 'Gap3'])
2220
lazy_import('sage.interfaces.genus2reduction', ['genus2reduction', 'Genus2reduction'])
2321
lazy_import('sage.interfaces.gfan', ['gfan', 'Gfan'])
2422
lazy_import('sage.interfaces.giac', ['giac', 'Giac'])
2523
lazy_import('sage.interfaces.gnuplot', 'gnuplot')
24+
lazy_import('sage.interfaces.gp', ['gp', 'gp_version', 'Gp'])
2625
lazy_import('sage.interfaces.kash', ['kash', 'kash_version', 'Kash'])
2726
lazy_import('sage.interfaces.lie', ['lie', 'LiE'])
2827
lazy_import('sage.interfaces.lisp', ['lisp', 'Lisp'])
2928
lazy_import('sage.interfaces.macaulay2', ['macaulay2', 'Macaulay2'])
29+
lazy_import('sage.interfaces.magma', ['magma', 'Magma'])
3030
lazy_import('sage.interfaces.magma_free', 'magma_free')
3131
lazy_import('sage.interfaces.maple', ['maple', 'Maple'])
3232
lazy_import('sage.interfaces.mathematica', ['mathematica', 'Mathematica'])
@@ -35,12 +35,14 @@
3535
lazy_import('sage.interfaces.mupad', ['mupad', 'Mupad']) # NOT functional yet
3636
lazy_import('sage.interfaces.mwrank', ['mwrank', 'Mwrank'])
3737
lazy_import('sage.interfaces.octave', ['octave', 'Octave'])
38+
lazy_import('sage.interfaces.polymake', 'polymake')
3839
lazy_import('sage.interfaces.povray', 'povray')
3940
lazy_import('sage.interfaces.psage', 'PSage')
4041
lazy_import('sage.interfaces.qepcad', ['qepcad', 'qepcad_version', 'qepcad_formula'])
4142
lazy_import('sage.interfaces.r', ['r', 'R', 'r_version'])
4243
lazy_import('sage.interfaces.read_data', 'read_data')
4344
lazy_import('sage.interfaces.scilab', 'scilab')
45+
lazy_import('sage.interfaces.singular', ['singular', 'singular_version', 'Singular'])
4446
lazy_import('sage.interfaces.tachyon', 'tachyon_rt')
4547

4648
# The following variable is used by sage-shell-mode in emacs:

src/sage/interfaces/expect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if
928928
929929
TESTS::
930930
931+
sage: from sage.interfaces.singular import singular
931932
sage: singular._eval_line('def a=3;')
932933
''
933934
sage: singular('a')

src/sage/interfaces/gap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if
644644
645645
TESTS::
646646
647+
sage: from sage.interfaces.gap import gap
647648
sage: gap._eval_line('2+2;')
648649
'4'
649650
@@ -1124,6 +1125,7 @@ def __reduce__(self):
11241125
"""
11251126
EXAMPLES::
11261127
1128+
sage: from sage.interfaces.gap import gap
11271129
sage: gap.__reduce__()
11281130
(<function reduce_load_GAP at 0x...>, ())
11291131
sage: f, args = _

src/sage/interfaces/gp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def _repr_(self):
270270
271271
EXAMPLES::
272272
273-
sage: gp # indirect doctest
273+
sage: gp # indirect doctest
274274
PARI/GP interpreter
275275
"""
276276
return 'PARI/GP interpreter'
@@ -279,6 +279,7 @@ def __reduce__(self):
279279
"""
280280
EXAMPLES::
281281
282+
sage: from sage.interfaces.gp import gp
282283
sage: gp.__reduce__()
283284
(<function reduce_load_GP at 0x...>, ())
284285
sage: f, args = _

src/sage/interfaces/interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ def __getattr__(self, attrname):
638638
TESTS::
639639
640640
sage: from sage.structure.parent_base import ParentWithBase
641+
sage: from sage.interfaces.singular import singular
641642
sage: ParentWithBase.__getattribute__(singular, '_coerce_map_from_')
642643
<bound method Singular._coerce_map_from_ of Singular>
643644
"""

src/sage/interfaces/magma.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ def __reduce__(self):
397397
398398
EXAMPLES::
399399
400+
sage: from sage.interfaces.magma import magma
400401
sage: loads(dumps(magma)) is magma
401402
True
402403

src/sage/interfaces/polymake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def __reduce__(self):
155155
"""
156156
EXAMPLES::
157157
158+
sage: from sage.interfaces.polymake import polymake
158159
sage: loads(dumps(polymake)) is polymake
159160
True
160161

src/sage/interfaces/singular.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ def __reduce__(self):
468468
"""
469469
EXAMPLES::
470470
471+
sage: from sage.interfaces.singular import singular
471472
sage: singular.__reduce__()
472473
(<function reduce_load_Singular at 0x...>, ())
473474
"""

0 commit comments

Comments
 (0)