Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tricky question about native extension packaging

Reply
Thread Tools

Tricky question about native extension packaging

 
 
olivierbourdon38@gmail.com
Guest
Posts: n/a
 
      02-10-2009
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

 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      02-10-2009
On Tue, Feb 10, 2009 at 8:42 AM, <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
packaging hybrid extension? Rick DeNatale Ruby 4 10-10-2006 03:05 AM
writing native ObjC extension to ruby ?? Yvon Thoraval Ruby 10 08-08-2006 08:12 AM
a tricky if else(maybe not tricky but impossible) nirkheys@gmail.com C Programming 9 04-25-2006 06:13 PM
Compiling native extension into Ruby David Craine Ruby 4 01-12-2005 11:42 AM
ruby-mysql native extension for mswin32 Sarah Tanembaum Ruby 1 12-19-2004 09:55 PM



Advertisments