Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#129 closed defect (duplicate)

relocation problem

Reported by: nbruin Owned by: was
Priority: minor Milestone:
Component: interfaces Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

When you build a sage tree at one location and then move it to another location, introspection is broken. Example:

NumberField??

would still quote an absolute file name in the old location and

NumberField???

would fail.

Change History (2)

comment:1 Changed 15 years ago by was

  • Resolution set to duplicate
  • Status changed from new to closed

This is trac #81.

comment:2 Changed 15 years ago by was

This is now fixed. I fixed it by creating the script below and calling it from the sage_setup() section of sage-sage:

#!/usr/bin/env sage.bin

import os

SAGE_ROOT = os.environ['SAGE_ROOT']

location_file = '%s/local/lib/sage-current-location.txt'%SAGE_ROOT

def install_moved():
    if not os.path.exists(location_file) or open(location_file).read() != SAGE_ROOT:
        open(location_file,'w').write(SAGE_ROOT)
        return True
    return False

def update_hardcoded_files(path):
    # The only known files with hard coded paths.
    if os.path.isdir(path):
        for X in os.listdir(path):
            update_hardcoded_files('%s/%s'%(path,X))
    else:
        P = path[-4:]
        if P == '.pyo' or P == '.pyc':
            try:
                os.unlink(path)
            except OSError, msg:
                print msg

if __name__ ==  '__main__':
    # Check if SAGE has moved, and if so delete all .pyo and .pyc files
    # in the python libs directory, so they are rebuilt. 
    if install_moved():
        print "The SAGE install tree may have moved."
        print "Regenerating files that hardcode the install PATH (please wait a few seconds)..."
        update_hardcoded_files(SAGE_ROOT + '/local/lib/python/')
Note: See TracTickets for help on using tickets.