Hello, I believe that relative cimports would be useful in Cython. (For a motivation, see my recent posting on cython-user http://thread.gmane.org/gmane.comp.python.cython.user/7401) So I tried to assess how much work it would be to implement that feature, but that's a tough job as I do not have a good overview of Cython's considerable code base. Would allowing relative cimports be a rather small thing comparable to commit 599c34053 which introduced relative imports (http://codereview.appspot.com/1734044/patch/2001/3001)? Or are there any issues that require serious refactoring? Christoph
Oh, something I forgot: in Cython/Compiler/Parsing.py I find code that emits "Relative cimport is not supported yet". However, when I try to compile code which includes a relative cimport, I do not get this error, but instead from .graph.defs cimport gint ^ ------------------------------------------------------------ kwant/_system.pyx:8:0: 'graph.defs.pxd' not found Is this related to the behavior of Pyrex? I tried creating a file "graph.defs.pxd" but I was unable to make the above line compile.
Christoph Groth wrote:
in Cython/Compiler/Parsing.py I find code that emits "Relative cimport is not supported yet".
Is this related to the behavior of Pyrex?
There's no such code in Pyrex's Parsing.py, and if I try to compile this with Pyrex: from .bar.stuff cimport thing I get /Users/greg/foo/foo.pyx:1:5: Expected an identifier -- Greg
On Mon, Oct 1, 2012 at 4:43 AM, Christoph Groth <cwg@falma.de> wrote:
Hello,
I believe that relative cimports would be useful in Cython. (For a motivation, see my recent posting on cython-user http://thread.gmane.org/gmane.comp.python.cython.user/7401)
So I tried to assess how much work it would be to implement that feature, but that's a tough job as I do not have a good overview of Cython's considerable code base. Would allowing relative cimports be a rather small thing comparable to commit 599c34053 which introduced relative imports (http://codereview.appspot.com/1734044/patch/2001/3001)? Or are there any issues that require serious refactoring?
This might be a simple as letting the import code (e.g. at https://github.com/cython/cython/blob/master/Cython/Utility/ImportExport.c and everywhere it's called) allow and use relative imports. At a high level, the tricky part is that cimports are resolved at Cython complile time, then again at runtime. IIRC there is also some name unification that uses the absolute path (which might not turn out to matter, but something to be aware of and look into). In short, I don't think it'd be that hard, but it'd probably touch a larger spread of the codebase than the relative (non-c)import case. - Robert
participants (3)
-
Christoph Groth -
Greg Ewing -
Robert Bradshaw