Tricky question about native extension packaging

Discussion in 'Python' started by olivierbourdon38@gmail.com, Feb 10, 2009.

  1. Guest

    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
     
    , Feb 10, 2009
    #1
    1. Advertising

  2. Chris Rebert Guest

    On Tue, Feb 10, 2009 at 8:42 AM, <> 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
     
    Chris Rebert, Feb 10, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    538
    CBFalconer
    Apr 25, 2006
  2. Sarah Tanembaum

    ruby-mysql native extension for mswin32

    Sarah Tanembaum, Dec 19, 2004, in forum: Ruby
    Replies:
    1
    Views:
    116
    Justin Rudd
    Dec 19, 2004
  3. David Craine

    Compiling native extension into Ruby

    David Craine, Jan 11, 2005, in forum: Ruby
    Replies:
    4
    Views:
    151
  4. Yvon Thoraval

    writing native ObjC extension to ruby ??

    Yvon Thoraval, Aug 7, 2006, in forum: Ruby
    Replies:
    10
    Views:
    214
    Robert Klemme
    Aug 8, 2006
  5. Rick DeNatale

    packaging hybrid extension?

    Rick DeNatale, Oct 9, 2006, in forum: Ruby
    Replies:
    4
    Views:
    91
    Rick DeNatale
    Oct 10, 2006
Loading...

Share This Page