#15184: CachedFunction file location seems problematic
--------------------------+-------------------------
       Reporter:  nbruin  |        Owner:
           Type:  defect  |       Status:  new
       Priority:  major   |    Milestone:  sage-5.12
      Component:  misc    |   Resolution:
       Keywords:          |    Merged in:
        Authors:          |    Reviewers:
Report Upstream:  N/A     |  Work issues:
         Branch:          |       Commit:
   Dependencies:          |     Stopgaps:
--------------------------+-------------------------

Comment (by nbruin):

 The logic above seems like a SAGE_ROOT-less translation of the code
 introduced on #11115, but I think something went wrong with a "leading
 slash" problem:
 {{{
 sage: sage.env.SAGE_LIB
 '/usr/local/sage/5.10/local/lib/python2.7/site-packages'
 sage: sage_getfile(M.is_field.f)
 '/usr/local/sage/5.10/local/lib/python2.7/site-
 packages/sage/rings/finite_rings/integer_mod_ring.py'
 sage: sage_getfile(M.is_field)
 '/sage/rings/finite_rings/integer_mod_ring.py'
 sage: sage.env.SAGE_LIB=sage.env.SAGE_LIB+'/'
 sage: sage_getfile(M.is_field)
 '/usr/local/sage/5.10/devel/sage/sage/rings/finite_rings/integer_mod_ring.py'
 }}}
 so it seems that if `_sage_doc_` ensures it returns a ''relative''
 filename, then `sage_getfile` will prefix the appropriate path, but if it
 returns an ''absolute'' path (which happens if we snap off 'SAGE_LIB' but
 not its slash separator) then of course it won't.

 Are we sure that the connecting slash is never there? Then we can just do
 `filename = filename[len(SAGE_LIB)+1:]`. Otherwise, perhaps we should do
 {{{
                 if filename.startswith(SAGE_SRC):
                     filename = filename[len(SAGE_SRC):]
                     if filename.startswith('/'):
                         filename = filename[1:]
                 elif filename.startswith(SAGE_LIB):
                     filename = filename[len(SAGE_LIB):]
                     if filename.startswith('/'):
                         filename = filename[1:]
 }}}
 By the way, is
 {{{
             try:
                 sourcelines = sage_getsourcelines(f)
             except IOError:
                 sourcelines = None
 }}}
 really the best way of checking that the file reported by
 `sage_getfile(f)` exists? We could just do a
 {{{
 try:
     open(sage_getfile(f),'r')
     file_exists=True
 except IOError:
     file_exists=False
 }}}
 which should be cheaper than actually rummaging through the entire file.
 The only thing we use later on is the starting line, and in many cases
 that would be available from elsewhere (e.g., the docstring), so we
 wouldn't need to actually read the source file.

--
Ticket URL: <http://trac.sagemath.org/ticket/15184#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to