Skip to content

Commit

Permalink
Trac #34283: Prevent circular import of matrix space
Browse files Browse the repository at this point in the history
The issue occurs randomly when testing ticket #34185 on a system with
the optional package meataxe being present. For example

{{{#!python
sage -tp --hide=meataxe src/sage/knots/
Traceback (most recent call last):
  File "/home/sebastian/devel/sage/src/bin/sage-runtests", line 157, in
<module>
    err = DC.run()
  File "/home/sebastian/devel/sage/local/var/lib/sage/venv-
python3.8/lib/python3.8/site-packages/sage/doctest/control.py", line
1439, in run
    if f.is_present():
  File "/home/sebastian/devel/sage/local/var/lib/sage/venv-
python3.8/lib/python3.8/site-packages/sage/features/__init__.py", line
182, in is_present
    res = self._is_present()
  File "/home/sebastian/devel/sage/local/var/lib/sage/venv-
python3.8/lib/python3.8/site-packages/sage/features/join_feature.py",
line 63, in _is_present
    test = f._is_present()
  File "/home/sebastian/devel/sage/local/var/lib/sage/venv-
python3.8/lib/python3.8/site-packages/sage/features/__init__.py", line
950, in _is_present
    importlib.import_module(self.name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in
import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in
_find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1174, in
exec_module
  File "<frozen importlib._bootstrap>", line 219, in
_call_with_frames_removed
  File "sage/matrix/matrix_gfpn_dense.pyx", line 1, in init
sage.matrix.matrix_gfpn_dense
(build/cythonized/sage/matrix/matrix_gfpn_dense.c:21852)
  File "sage/matrix/matrix_dense.pyx", line 1, in init
sage.matrix.matrix_dense
(build/cythonized/sage/matrix/matrix_dense.c:7897)
  File "sage/matrix/matrix2.pyx", line 1, in init sage.matrix.matrix2
(build/cythonized/sage/matrix/matrix2.c:127958)
  File "sage/matrix/matrix1.pyx", line 1, in init sage.matrix.matrix1
(build/cythonized/sage/matrix/matrix1.c:25542)
  File "sage/matrix/matrix0.pyx", line 28, in init sage.matrix.matrix0
(build/cythonized/sage/matrix/matrix0.c:45663)
  File "/home/sebastian/devel/sage/local/var/lib/sage/venv-
python3.8/lib/python3.8/site-packages/sage/modules/free_module.py", line
182, in <module>
    import sage.matrix.matrix_space
  File "/home/sebastian/devel/sage/local/var/lib/sage/venv-
python3.8/lib/python3.8/site-packages/sage/matrix/matrix_space.py", line
40, in <module>
    from . import matrix_generic_dense
  File "sage/matrix/matrix_generic_dense.pyx", line 1, in init
sage.matrix.matrix_generic_dense
(build/cythonized/sage/matrix/matrix_generic_dense.c:6637)
AttributeError: partially initialized module 'sage.matrix.matrix_dense'
has no attribute 'Matrix_dense' (most likely due to a circular import)
}}}

Of course this also occurs (randomly) with option `--hide=all` or
`--hide=optional`.

Part of Meta-ticket #33580: make all modules importable without sage.all

URL: https://trac.sagemath.org/34283
Reported by: soehms
Ticket author(s): Sebastian Oehms
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Aug 29, 2022
2 parents cb618a3 + 53d8d11 commit 42beee4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/sage/matrix/matrix_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
import sys
import operator

# Sage matrix imports
from . import matrix_generic_dense
from . import matrix_generic_sparse
# Sage matrix imports see :trac:`34283`

# Sage imports
import sage.structure.coerce
Expand Down Expand Up @@ -303,7 +301,8 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation):
return matrix_mpolynomial_dense.Matrix_mpolynomial_dense

# The fallback
return matrix_generic_dense.Matrix_generic_dense
from sage.matrix.matrix_generic_dense import Matrix_generic_dense
return Matrix_generic_dense

# Deal with request for a specific implementation
if implementation == 'flint':
Expand Down Expand Up @@ -360,7 +359,8 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation):
raise ValueError("'linbox-double' matrices can only deal with order < %s" % matrix_modn_dense_double.MAX_MODULUS)

if implementation == 'generic':
return matrix_generic_dense.Matrix_generic_dense
from sage.matrix.matrix_generic_dense import Matrix_generic_dense
return Matrix_generic_dense

if implementation == 'gap':
from .matrix_gap import Matrix_gap
Expand Down Expand Up @@ -402,7 +402,8 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation):
return matrix_double_sparse.Matrix_double_sparse

# the fallback
return matrix_generic_sparse.Matrix_generic_sparse
from sage.matrix.matrix_generic_sparse import Matrix_generic_sparse
return Matrix_generic_sparse



Expand Down

0 comments on commit 42beee4

Please sign in to comment.