On Jun 11, 2009, at 12:07 PM, Ondrej Certik wrote:

> On Thu, Jun 11, 2009 at 1:02 PM, Ondrej Certik<[email protected]>  
> wrote:
>> On Thu, Jun 11, 2009 at 12:40 PM, Stefan  
>> Behnel<[email protected]> wrote:
>>>
>>> Lisandro Dalcin wrote:
>>>> On Thu, Jun 11, 2009 at 2:31 PM, Ondrej Certik<[email protected]>  
>>>> wrote:
>>>>> As far as Cython is concerned, the only problem I can see is  
>>>>> that it
>>>>> changes all import paths to the fully qualified import paths.  
>>>>> Python
>>>>> allows both ways, Cython only the fully qualified way. As Stefan
>>>>> explained, this is needed, because it will then not work  
>>>>> properly at
>>>>> the moment. But I am not convinced this cannot be fixed --  
>>>>> though it
>>>>> may happen that the fix is too tedious and not worthy.
>>>>>
>>>>
>>>> IMHO, the only "fix" Cython needs is support for relative  
>>>> imports...
>>>> Then you could write:
>>>>
>>>> from ._hermes2d cimport what_you_need
>>>>
>>>> This way, Ondrej would be able to easily write Cython code using
>>>> relative imports the right way...
>>>
>>> I thought about this, too, and yes, that would be a nice feature.  
>>> But it
>>> doesn't help in this case. What Ondrej wanted was to be able to  
>>> import the
>>> module both from its package and as a plain import, i.e. when put  
>>> outside
>>> of any package. The above would not handle the latter case either.
>>
>> I think it would. I have _forms.so and _hermes2d.so. The _hermes2d.so
>> is imported from _forms.so and if the import was relative, e.g. if
>> _forms.so was doing "import ._hermes2d", then it should work both in
>> the tree and out of the tree.
>
> Looking here, it should be easy to support relative imports:
>
> http://docs.python.org/c-api/import.html
>
> so unless there is some difficulty inside Cython, that I don't see yet
> (e.g. the kind of thing Stefan was talking about), it should be
> possible to support relative imports quite easily, I already
> understand the part that takes the import path from .pyx file and then
> makes it fully qualified --- so I would simply change that.

Cython does support relative cimports (we use them all over in Sage).  
What it does not support is deciding a modules fully qualified name  
at runtime because it uses this information at compile time. (It is  
possible that this could be changed, I haven't thought of what the  
repercussions should be).

What I don't understand, in your setup, is how are you handling

foo.py
foo2.pyx
a/__init__.py
a/bar.pyx
a/bar.pxd

Now when foo.py does "from a.bar import *" or foo2.pyx does "from  
a.bar cimport *" how does this get resolved if the .so files are  
moved to the top level?

- Robert


_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to