Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in handling attached pyx-files #4336

Closed
simon-king-jena opened this issue Oct 22, 2008 · 7 comments
Closed

Bug in handling attached pyx-files #4336

simon-king-jena opened this issue Oct 22, 2008 · 7 comments

Comments

@simon-king-jena
Copy link
Member

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

CC: @robertwb

Component: misc

Keywords: attachments

Issue created by migration from https://trac.sagemath.org/ticket/4336

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Oct 22, 2008

comment:1

Added RobertWB to the CC since he worked on the Cython recompilation patch.

Simon: Are you sure you edited the right cython.py - there are several copies in the tree.

Cheers,

Michael

@simon-king-jena
Copy link
Member Author

comment:2

Dear Michael,

Replying to @sagetrac-mabshoff:

Simon: Are you sure you edited the right cython.py - there are several copies in the tree.

I chose local/lib/python2.5/site-packages/sage/misc/cython.py

Which should I take instead?

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Oct 22, 2008

comment:3

Replying to @simon-king-jena:

Dear Michael,

Replying to @sagetrac-mabshoff:

Simon: Are you sure you edited the right cython.py - there are several copies in the tree.

I chose local/lib/python2.5/site-packages/sage/misc/cython.py

Which should I take instead?

Take the one in $SAGE_ROOT/devel/sage/..

Cheers,

Michael

@simon-king-jena
Copy link
Member Author

comment:4

Dear Michael, dear Robert,

Replying to @sagetrac-mabshoff:

Which should I take instead?

Take the one in $SAGE_ROOT/devel/sage/..

Did already. It works, the traceback disappears. Patch'll follow!

Cheers,
Simon

@simon-king-jena
Copy link
Member Author

Attachment: attach_bugfix.patch.gz

Fixes a bug that occurs when an attached .pyx file is changed

@simon-king-jena simon-king-jena changed the title [with suggested solution] Bug in handling attached pyx-files Bug in handling attached pyx-files Oct 22, 2008
@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Oct 27, 2008

comment:6

Simon's patch is correct. This was actually broken by the patch in #4238.

Cheers,

Michael

@sagetrac-mabshoff sagetrac-mabshoff mannequin modified the milestones: sage-3.2.1, sage-3.2 Oct 27, 2008
@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Oct 27, 2008

comment:7

Merged in Sage 3.2.alpha1

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Oct 27, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant