[Cython] import relative cimport

Robert Bradshaw robertwb at gmail.com
Tue Oct 2 02:08:45 CEST 2012


On Mon, Oct 1, 2012 at 4:43 AM, Christoph Groth <cwg at 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


More information about the cython-devel mailing list