Tricky question about native extension packaging

Chris Rebert clp2 at rebertia.com
Tue Feb 10 14:46:24 EST 2009


On Tue, Feb 10, 2009 at 8:42 AM,  <olivierbourdon38 at gmail.com> wrote:
> let's assume I (almost) have and extension available as a C file and
> the setup.py and I want to generate from this single c file 2 .so
> files using
>
> cc -DOPTION1 x.c to produce x_1.so
> cc -DOPTION2 x.c to produce x_2.so
>
> and at runtime depending of my OS version either load x_1 or x_2

I don't know about the setup.py part of your question, but as for
choosing between 2 modules at runtime:

#file foo.py
#assuming 'foo' is the desired name of the module
from sys import platform
SUN = 'sunos5'
LINUX = 'linux2'
WIN = 'win32'

if platform == SUN:
    from x_1 import *
elif platform == LINUX:
    from x_2 import *
elif platform == WIN:
    from x_1 import *
else:
    raise RuntimeError, "Unknown/unsupported platform"


Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list