#12868: Attaching a pyx file in the presence of __init__.py results in wrong
module
names
-----------------------------+----------------------------------------------
Reporter: SimonKing | Owner: jason
Type: defect | Status: new
Priority: major | Milestone: sage-5.1
Component: misc | Resolution:
Keywords: | Work issues:
Report Upstream: N/A | Reviewers:
Authors: | Merged in:
Dependencies: | Stopgaps:
-----------------------------+----------------------------------------------
Comment (by leif):
Replying to [comment:8 SimonKing]:
> Replying to [comment:7 leif]:
> > Currently changing the patch to remove the (in your opinion)
undesirable link to `__init__.py` earlier, such that `cython`, when
invoked, won't see it.
>
> That wouldn't be a solution. Perhaps the user ''wants'' (for some
reason) to have it in the folder (in particular, it is no user error).
In the temporary build folder? Not sure whether there are situations
where this is needed.
This one works for me:
{{{
#!patch
diff --git a/sage/misc/cython.py b/sage/misc/cython.py
--- a/sage/misc/cython.py
+++ b/sage/misc/cython.py
@@ -382,6 +382,10 @@
os.system(cmd)
if os.path.exists("%s/setup.py" % build_dir):
os.unlink("%s/setup.py" % build_dir)
+ if os.path.exists("%s/__init__.py" % build_dir):
+ sys.stderr.write("Note: Ignoring %s/__init__.py ...\n" %
abs_base)
+ sys.stderr.flush()
+ os.unlink("%s/__init__.py" % build_dir)
if compile_message:
print "Compiling %s..."%filename
}}}
No idea whether it breaks anything else. Note that you have to run
`./sage -b` after changing the file, which in turn causes (for whatever
reason) dozens of extension modules to get rebuilt.
In case having `__init__.py` in the temporary build directory is
desirable, we could just restore the link after Cython has been run.
[[BR]]
> I believe that it should simply not matter for attaching files whether
or not `__init__.py` is there. Of course, if you have a Python file and
want that you can import (not attach) it, then you would create the
`__init__.py` (this is why I created it, anyway).
>
> Attaching a file should be independent from importing, and both should
simultaneously be possible. So, unlinking `__init__.py` is bad.
Importing in the usual way should still work, since you don't import from
the temporary directory, do you?
[[BR]]
> Up to yesterday, I was in the belief that "attaching a pyx-file means"
that
>
> 1. the file is copied into a temporary directory,
> 2. the compilation is done there, and
> 3. the module is imported from the temporary directory.
That's correct. But in addition, symbolic links to any(!) file in the
directory containing the attached file are created in the temporary
directory (since e.g. you otherwise wouldn't be able to import or include
other files in that directory from the attached file). Above, I've only
changed that part.
> Since the temporary directory would not contain `__init__.py`, there
should be no problem, isn't it?
That's what I was saying. (Unless you try to `import __init__` in the
attached file...)
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12868#comment:9>
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 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.