Ticket #7377: trac_7377-lazy-maxlib.patch

File trac_7377-lazy-maxlib.patch, 1.5 KB (added by nbruin, 8 years ago)

Improves startup time by lazily loading maxima_lib in calculus

  • sage/calculus/calculus.py

    # HG changeset patch
    # User Nils Bruin <nbruin@sfu.ca>
    # Date 1298778069 28800
    # Node ID b41f2d4bc008dccc4a444188d6630090e9e1b4db
    # Parent  5a8bc0eaef71c044f6c0e0518566fee3c7a7ee1e
    Make calculus load its maxima instance in a lazy way
    
    diff -r 5a8bc0eaef71 -r b41f2d4bc008 sage/calculus/calculus.py
    a b  
    383383    sage: sage.calculus.calculus.maxima('f1')
    384384    f1
    385385"""
    386 import sage.interfaces.maxima_lib
    387 maxima = sage.interfaces.maxima_lib.maxima_lib
     386class lazy(object):
     387    def __init__(self):
     388        pass
     389   
     390    def __getattr__(self,key):
     391        import sage.interfaces.maxima_lib
     392        sage.calculus.calculus.maxima = sage.interfaces.maxima_lib.maxima
     393        return getattr(sage.interfaces.maxima_lib.maxima,key)
     394
     395    def __hasattr__(self, key):
     396        import sagge.interfaces.maxima_lib
     397        sage.calculus.calculus.maxima = sage.interfaces.maxima_lib.maxima
     398        return hasattr(sage.interfaces.maxima_lib.maxima,key)
     399
     400    def __setattr__(self, key, value):
     401        import sage.interfaces.maxima_lib
     402        sage.calculus.calculus.maxima = sage.interfaces.maxima_lib.maxima
     403        return setattr(sage.interfaces.maxima_lib.maxima, key, value)
     404
     405maxima = lazy()
    388406# This is not the same instance of Maxima as the general purpose one
    389407#from sage.interfaces.maxima import Maxima
    390408#maxima = Maxima(init_code = ['display2d : false', 'domain : complex',