#4336: [with suggested solution] Bug in handling attached pyx-files
-----------------------+----------------------------------------------------
 Reporter:  SimonKing  |       Owner:  cwitty             
     Type:  defect     |      Status:  new                
 Priority:  critical   |   Milestone:  sage-3.2           
Component:  misc       |    Keywords:  attachments, cython
-----------------------+----------------------------------------------------
 I attached a pyx-file:
 {{{
 sage: attach f5.pyx
 Compiling /home/king/Projekte/f5/f5.pyx...
 }}}

 Then I changed the file on the disk, and pressed the `Enter` key in Sage.
 This should result in a recompilation of `f5.pyx`, but instead I got this
 traceback:
 {{{
 sage:
 Compiling /home/king/Projekte/f5/f5.pyx...
 ---------------------------------------------------------------------------
 UnboundLocalError                         Traceback (most recent call
 last)

 /home/king/SAGE/devel/sage-3.1.4/local/lib/python2.5/site-
 packages/sage/misc/interpreter.pyc in sage_prefilter(self, block,
 continuation)
     394         for i in range(len(B)):
     395             L = B[i]
 --> 396             M = do_prefilter_paste(L, continuation or (not first))
     397             first = False
     398             # The L[:len(L)-len(L.lstrip())]  business here
 preserves

 /home/king/SAGE/devel/sage-3.1.4/local/lib/python2.5/site-
 packages/sage/misc/interpreter.pyc in do_prefilter_paste(line,
 continuation)
     190                         _ip.runlines('%%run -i
 "%s"'%preparse_file_named(F))
     191                     elif F.endswith('.spyx') or
 F.endswith('.pyx'):
 --> 192                         X = load_cython(F)
     193                         __IPYTHON__.push(X)
     194                     else:

 /home/king/SAGE/devel/sage-3.1.4/local/lib/python2.5/site-
 packages/sage/misc/interpreter.pyc in load_cython(name)
     340     cur = os.path.abspath(os.curdir)
     341     try:
 --> 342         mod, dir  = cython.cython(name, compile_message=True,
 use_cache=True)
     343     except (IOError, OSError, RuntimeError), msg:
     344         print "Error compiling cython file:\n%s"%msg

 /home/king/SAGE/devel/sage-3.1.4/local/lib/python2.5/site-
 packages/sage/misc/cython.pyc in cython(filename, verbose,
 compile_message, use_cache, create_local_c_file, annotate, sage_namespace,
 create_local_so_file)
     311                                         for fname in
 additional_source_files])
     312
 --> 313     pyx = '%s/%s.pyx'%(build_dir, name)
     314     open(pyx,'w').write(F)
     315     setup="""

 UnboundLocalError: local variable 'name' referenced before assignment
 }}}

 Afterwards, leaving Sage was impossible using `quit` -- I got the same
 traceback again and had to quit with `Ctrl-D`.

 I think the problem is in lines 299-311 of `cython.py`, which is
 {{{
     if create_local_so_file:
         name = base
     else:
         global sequence_number
         if not sequence_number.has_key(base):
             sequence_number[base] = 0
             name = '%s_%s'%(base, sequence_number[base])

             # increment the sequence number so will use a different one
 next time.
             sequence_number[base] += 1

     additional_source_files =
 ",".join(["'"+os.path.abspath(os.curdir)+"/"+fname+"'" \
                                         for fname in
 additional_source_files])
 }}}

 If I'm not mistaken, there is a wrong indentation, and it should be
 {{{
     if create_local_so_file:
         name = base
     else:
         global sequence_number
         if not sequence_number.has_key(base):
             sequence_number[base] = 0
         name = '%s_%s'%(base, sequence_number[base])

         # increment the sequence number so will use a different one next
 time.
         sequence_number[base] += 1

     additional_source_files =
 ",".join(["'"+os.path.abspath(os.curdir)+"/"+fname+"'" \
                                         for fname in
 additional_source_files])
 }}}

 Problem 1: I have no idea how I can force Sage to use the modified
 `cython.py`, hence I can not test my changes.

 Problem 2: `hg_sage.commit()` did not work, since it claimed that nothing
 was changed (although `cython.py` did change). So, no patch.

 Can you give me a solution to Problems 1 and 2? And does my suggested
 solution works?
 Cheers
       Simon

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/4336>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of 
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to