Ticket #12670: trac_12670-lazy-cache.patch

File trac_12670-lazy-cache.patch, 1.6 KB (added by jhpalmieri, 8 years ago)

(Sage library)

  • sage/misc/lazy_import.pyx

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1331758137 25200
    # Node ID 3998d8579b9c341c3b572d14730f3534d9607e25
    # Parent  1c4d74f2d7fbd35579b14814afd622771d1f03f2
    Store lazy import cache files in .sage/cache/ instead of in .sage/
    
    diff --git a/sage/misc/lazy_import.pyx b/sage/misc/lazy_import.pyx
    a b def save_cache_file(): 
    871871        star_imports = {}
    872872    _, tmp_file = tempfile.mkstemp()
    873873    pickle.dump(star_imports, open(tmp_file, "w"))
     874    cache_dir = os.path.dirname(get_cache_file())
     875    try:
     876        os.makedirs(cache_dir)
     877    except OSError:
     878        # Probably failed because directory already exists, but we make sure.
     879        if not os.path.isdir(cache_dir):
     880            raise
    874881    shutil.move(tmp_file, get_cache_file())
    875882
    876883def get_star_imports(module_name):
  • sage/misc/lazy_import_cache.py

    diff --git a/sage/misc/lazy_import_cache.py b/sage/misc/lazy_import_cache.py
    a b  
    11"""
    2 This is a pure Python file with no dependancies so it can be used in setup.py.
     2This is a pure Python file with no dependencies so it can be used in setup.py.
    33"""
    44
    55import os
    def get_cache_file(): 
    2828        sage: os.environ['DOT_SAGE'] = OLD
    2929    """
    3030    mangled = os.path.realpath(os.path.join(os.environ['SAGE_ROOT'], 'devel', 'sage')).replace(os.sep, '_')
    31     return os.path.join(os.environ['DOT_SAGE'],
     31    return os.path.join(os.environ['DOT_SAGE'], 'cache',
    3232                        "%s-lazy_import_cache.pickle" % mangled)