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

Commit

Permalink
Do not import sagenb at Sage startup
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Jan 8, 2014
1 parent 037277a commit 4b2c470
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 43 deletions.
87 changes: 52 additions & 35 deletions src/sage/all.py
Expand Up @@ -4,37 +4,52 @@
TESTS:
This is to test #10570. If the number of stackframes at startup
changes due to a patch you made, please check that this was an
intended effect of your patch.
::
sage: import gc
sage: import inspect
sage: from sage import *
sage: frames=[x for x in gc.get_objects() if inspect.isframe(x)]
We exclude the known files and check to see that there are no others::
sage: import os
sage: allowed = [os.path.join("lib","python","threading.py")]
sage: allowed.append(os.path.join("lib","python","multiprocessing"))
sage: allowed.append(os.path.join("sage","doctest"))
sage: allowed.append(os.path.join("bin","sage-runtests"))
sage: allowed.append(os.path.join("site-packages","IPython"))
sage: allowed.append(os.path.join("bin","sage-ipython"))
sage: allowed.append("<ipython console>")
sage: allowed.append("<doctest sage.all[3]>")
sage: allowed.append(os.path.join("sage","combinat","species","generating_series.py"))
sage: for i in frames:
....: filename, lineno, funcname, linelist, indx = inspect.getframeinfo(i)
....: for nm in allowed:
....: if nm in filename:
....: break
....: else:
....: print filename
....:
This is to test :trac:`10570`. If the number of stackframes at startup
changes due to a patch you made, please check that this was an
intended effect of your patch.
::
sage: import gc
sage: import inspect
sage: from sage import *
sage: frames = [x for x in gc.get_objects() if inspect.isframe(x)]
We exclude the known files and check to see that there are no others::
sage: import os
sage: allowed = [os.path.join("lib","python","threading.py")]
sage: allowed.append(os.path.join("lib","python","multiprocessing"))
sage: allowed.append(os.path.join("sage","doctest"))
sage: allowed.append(os.path.join("bin","sage-runtests"))
sage: allowed.append(os.path.join("site-packages","IPython"))
sage: allowed.append(os.path.join("bin","sage-ipython"))
sage: allowed.append("<ipython console>")
sage: allowed.append("<doctest sage.all[3]>")
sage: allowed.append(os.path.join("sage","combinat","species","generating_series.py"))
sage: for i in frames:
....: filename, lineno, funcname, linelist, indx = inspect.getframeinfo(i)
....: for nm in allowed:
....: if nm in filename:
....: break
....: else:
....: print filename
....:
Check that the Sage Notebook is not imported at startup (see
:trac:`15335`)::
sage: sagenb
Traceback (most recent call last):
...
NameError: name 'sagenb' is not defined
Check lazy import of ``interacts``::
sage: type(interacts)
<type 'sage.misc.lazy_import.LazyImport'>
sage: interacts
<module 'sage.interacts.all' from '...'>
"""

#*****************************************************************************
Expand Down Expand Up @@ -154,10 +169,12 @@

from sage.matroids.all import *

# The new separated Sage notebook
from sagenb.notebook.all import *

import sage.interacts.all as interacts
# Lazily import notebook functions and interacts (#15335)
lazy_import('sagenb.notebook.notebook_object', 'notebook')
lazy_import('sagenb.notebook.notebook_object', 'inotebook')
lazy_import('sagenb.notebook.sage_email', 'email')
lazy_import('sagenb.notebook.interact', 'interact')
lazy_import('sage.interacts', 'all', 'interacts')
from sage.interacts.debugger import debug

from copy import copy, deepcopy
Expand Down
2 changes: 2 additions & 0 deletions src/sage/all_notebook.py
@@ -1,4 +1,6 @@
from sage.all import *
from sagenb.notebook.all import *

preparser(on=True)

from sage.calculus.predefined import x
Expand Down
8 changes: 7 additions & 1 deletion src/sage/doctest/forker.py
Expand Up @@ -2080,7 +2080,13 @@ def __call__(self, options, outtmpfile=None, msgfile=None, result_queue=None):
N = options.file_iterations
results = DictAsObject(dict(walltime=[],cputime=[],err=None))
for it in range(N):
sage_namespace = RecordingDict(dict(sage.all_cmdline.__dict__))
# Make the right set of globals available to doctests
if options.sagenb:
import sage.all_notebook
sage_all = sage.all_notebook
else:
sage_all = sage.all_cmdline
sage_namespace = RecordingDict(sage_all.__dict__)
sage_namespace['__name__'] = '__main__'
sage_namespace['__package__'] = None
doctests, extras = self.source.create_doctests(sage_namespace)
Expand Down
1 change: 0 additions & 1 deletion src/sage/interacts/__init__.py
@@ -1 +0,0 @@
import all
4 changes: 3 additions & 1 deletion src/sage/interacts/library.py
Expand Up @@ -34,7 +34,9 @@


from sage.all import *
x=SR.var('x')
from sagenb.notebook.interact import *

x = SR.var('x')

def library_interact(f):
"""
Expand Down
5 changes: 1 addition & 4 deletions src/sage/misc/messaging.py
Expand Up @@ -4,18 +4,15 @@
Various interfaces to messaging services. Currently:
- ``pushover`` - a platform for sending and receiving push notifications
- ``email`` - an interface to e-mail
are supported.
is supported.
AUTHORS:
- Martin Albrecht (2012) - initial implementation
"""
pushover_defaults = {"token": "Eql67F14ohOZJ0AtEBJJU7FiLAk8wK"}

from sagenb.notebook import sage_email as email

def pushover(message, **kwds):
"""
Send a push notification with ``message`` to ``user`` using https://pushover.net/.
Expand Down
4 changes: 3 additions & 1 deletion src/sage/misc/sagedoc.py
Expand Up @@ -37,7 +37,6 @@
import pydoc
from sage.misc.viewer import browser
from sage.misc.misc import tmp_dir
from sagenb.misc.sphinxify import sphinxify
import sage.version
from sage.env import SAGE_DOC, SAGE_SRC

Expand Down Expand Up @@ -198,6 +197,7 @@ def detex(s, embedded=False):
if not embedded: # not in the notebook
s = _rmcmd(s, 'mathop')
s = _rmcmd(s, 'mathrm')
from sagenb.misc.sphinxify import sphinxify
s = sphinxify(s, format='text')
for a,b in math_substitutes: # do math substitutions
s = s.replace(a,b)
Expand Down Expand Up @@ -1279,6 +1279,7 @@ def __call__(self, obj, output='html', view=True):

# now s should be the reST version of the docstring
if output == 'html':
from sagenb.misc.sphinxify import sphinxify
html = sphinxify(s)
if view:
path = os.path.join(tmp_dir(), "temp.html")
Expand Down Expand Up @@ -1347,6 +1348,7 @@ def __call__(self, obj, output='html', view=True):
elif output == 'rst':
return s
elif output == 'text':
from sagenb.misc.sphinxify import sphinxify
return sphinxify(s, format='text')
else:
raise ValueError, "output type %s not recognized" % output
Expand Down

0 comments on commit 4b2c470

Please sign in to comment.