Tricky question about native extension packaging

O

olivierbourdon38

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

any (easy) way to do that and deliver the result as a single .egg
file ? What should the setup.py look like ?

Thanks for any insight
 
C

Chris Rebert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top