Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
using an old attachment to make a git branch (lazy import checks)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Chapoton committed Dec 3, 2018
1 parent d45ef02 commit 094921c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/sage/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
from sage.algebras.all import *
from sage.modular.all import *
from sage.sat.all import *
from sage.schemes.all import *
lazy_import("sage.schemes.all", "*", overwrite=False)
from sage.graphs.all import *
from sage.groups.all import *
from sage.arith.power import generic_power as power
Expand Down Expand Up @@ -263,6 +263,7 @@ def quit_sage(verbose=True):

# Cache the contents of star imports.
sage.misc.lazy_import.save_cache_file()
sage.misc.lazy_import._sage_all_import_done = True


### Debugging for Singular, see trac #10903
Expand Down Expand Up @@ -319,6 +320,7 @@ def _write_started_file():
# From now on it is ok to resolve lazy imports
sage.misc.lazy_import.finish_startup()


def sage_globals():
r"""
Return the Sage namespace.
Expand Down
32 changes: 31 additions & 1 deletion src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ def get_star_imports(module_name):
[...]
sage: os.remove(cache_file)
"""
global star_imports
global star_imports, _sage_all_import_done
if star_imports is None:
star_imports = {}
try:
Expand All @@ -1152,14 +1152,44 @@ def get_star_imports(module_name):
try:
return star_imports[module_name]
except KeyError:
all_done = sage_all_import_done
_sage_all_import_done = True # so that checks pass
module = __import__(module_name, {}, {}, ["*"])
_sage_all_import_done = all_done
if hasattr(module, "__all__"):
all = module.__all__
else:
all = [key for key in dir(module) if key[0] != "_"]
star_imports[module_name] = all
return all

# Utility functions for asserting that things stay lazily imported.


_sage_all_import_done = False


def check_lazy(module_name=None):
"""
Used to assert lazily imported modules do not actually get imported
during the import of sage.all is done.
TESTS::
sage: from sage.misc.lazy_import import check_lazy
sage: check_lazy("foo")
True
sage: sage.misc.lazy_import._sage_all_import_done = False
sage: check_lazy("foo")
False
sage: sage.misc.lazy_import._sage_all_import_done = True
sage: check_lazy("foo")
True
"""
if module_name is None:
module_name = inspect.currentframe().f_globals['__name__']
return _sage_all_import_done


# Add support for _instancedoc_
from sage.docs.instancedoc import instancedoc
Expand Down
2 changes: 2 additions & 0 deletions src/sage/schemes/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#
# http://www.gnu.org/licenses/
#*****************************************************************************
import sage.misc.lazy_import
assert sage.misc.lazy_import.check_lazy()

from .jacobians.all import *

Expand Down

0 comments on commit 094921c

Please sign in to comment.