[MERGE] import both c-extension and python module with the same name for testing

John Arbash Meinel john at arbash-meinel.com
Thu Aug 9 15:26:39 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Belchenko wrote:
> Lukáa Lalinský ?8H5B:
>> On `t, 2007-08-09 at 10:55 +1000, Martin Pool wrote:
>>> To try and summarize the thread: there are a few choices
>>>
>>>  1- merge something like Alexander's patch; then any module that wants
>>> a doubly-implemented module can just simply import it and will get
>>> either the C or python version
>>>  2- put the try/import/except/import into things that need to import it
>>>  3- have a pure-python wrapper module that imports whichever
>>> implementation is available
>>>
>> [...]
>>> Anything else?
>> Bzrlib already has two Pyrex extensions, but it is likely that there
>> will be more of them in the future. What about compiling them all into a
>> single extension (e.g. bzrlib._ext). The modules contain quite low-level
>> code which needs to be imported in almost all cases, anyway. I'm not
>> sure how big overhead have dynamic linkers on all bzr-supported
>> platforms, but I expect it to be bigger than for example the overhead of
>> try/except in case of importing the Python modules.
> 
> It will lead to mess in namespace of this big-one extension module.
> I don't think it's a right thing.
> 
> [µ]

Pyrex does have support for compiling multiple modules into a single
file. I'm just not sure how it exactly works.

Specifically, you can do something like:

Extension('bzrlib._ext', ['module_one', 'module_two'])

So far, I've only done:

Extension('bzrilb._foo', ['bzrlib/_foo.pyx'])

I have actually thought it could be good to have a single extension. My
big reason is that I think loading 1 extension will be faster than
loading multiple.

What I don't understand is how you are able to extract code when you do
that sort of thing. If I have _foo.pyx with a function 'foo'. And I
compile it to "bzrlib._ext", do I "from bzrlib._ext import foo" ?

If that is the case, then Alexander has a good reason to be worried
about namespace polution. We certainly expect that each file will have
its own namespace.

Anyway, if someone wants to take the time to try different pyrex
situations, I would be interested to hear what happens.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGuyQfJdeBCYSNAAMRAkepAKDM2VgpRpuKJtjJX0++G6WWJ+UwKQCfRUS+
Is7KYhPCmTORABrmH0hAyVs=
=VH7N
-----END PGP SIGNATURE-----



More information about the bazaar mailing list