Re: Statically linked extension and relative import

2009-05-07 Thread David Cournapeau
On Thu, May 7, 2009 at 8:34 PM, Andrew MacIntyre
 wrote:
> David Cournapeau wrote:
>>
>> Hi,
>>
>> I am trying to build a 3rd party extension and link it statically to
>> python. I managed to get things working by customizing Setup.local in
>> python source tree, but I have a problem for imports of the 'foo.bar'
>> form. For example, let's say the 3rd party module is laid out as
>> follows:
>>
>> foo/__init__.py
>> foo/bar.so
>>
>> and __init__.py contains:
>> import foo.bar
>>
>> I can build the bar extension and link it statically to python such as
>> from python, "import bar" works. But how can I make it "recognize"
>> "from foo import bar" ? I tried to understand how this works at the C
>> level in import.c, but I am a bit lost in the code. The ultimate goal
>> is to manage to get code coverage of the C code of the extension
>> through gcov, which does not support coverage of shared libraries ATM.
>
> If you link the bar extension statically, it is not in the foo package
> namespace (which is why "import bar" works),

Yes, I understand this.

> so should be imported as bar
> in foo's __init__.py.
>
> from foo import bar

But then I have to modify the 3rd party package for statically linked
versions. This means in particular that the same source cannot be used
for static and dynamic builds ?

cheers,

David
--
http://mail.python.org/mailman/listinfo/python-list


Re: Statically linked extension and relative import

2009-05-07 Thread Andrew MacIntyre

David Cournapeau wrote:

Hi,

I am trying to build a 3rd party extension and link it statically to
python. I managed to get things working by customizing Setup.local in
python source tree, but I have a problem for imports of the 'foo.bar'
form. For example, let's say the 3rd party module is laid out as
follows:

foo/__init__.py
foo/bar.so

and __init__.py contains:
import foo.bar

I can build the bar extension and link it statically to python such as
from python, "import bar" works. But how can I make it "recognize"
"from foo import bar" ? I tried to understand how this works at the C
level in import.c, but I am a bit lost in the code. The ultimate goal
is to manage to get code coverage of the C code of the extension
through gcov, which does not support coverage of shared libraries ATM.


If you link the bar extension statically, it is not in the foo package
namespace (which is why "import bar" works), so should be imported as bar
in foo's __init__.py.

from foo import bar

should then work from other code by virtue of the package namespace
(instantiated by __init__.py) then having a bar symbol.

--
-
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: andy...@bullseye.apana.org.au  (pref) | Snail: PO Box 370
   andy...@pcug.org.au (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
--
http://mail.python.org/mailman/listinfo/python-list


Statically linked extension and relative import

2009-05-07 Thread David Cournapeau
Hi,

I am trying to build a 3rd party extension and link it statically to
python. I managed to get things working by customizing Setup.local in
python source tree, but I have a problem for imports of the 'foo.bar'
form. For example, let's say the 3rd party module is laid out as
follows:

foo/__init__.py
foo/bar.so

and __init__.py contains:
import foo.bar

I can build the bar extension and link it statically to python such as
from python, "import bar" works. But how can I make it "recognize"
"from foo import bar" ? I tried to understand how this works at the C
level in import.c, but I am a bit lost in the code. The ultimate goal
is to manage to get code coverage of the C code of the extension
through gcov, which does not support coverage of shared libraries ATM.

thanks,

David
--
http://mail.python.org/mailman/listinfo/python-list