Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > portable extensions options for external libraries

Reply
Thread Tools

portable extensions options for external libraries

 
 
Alexandre Guimond
Guest
Posts: n/a
 
      10-18-2006
Hi.

I want to create a portable setup.py file for windows / linux for an
extension package that i need to link with external libraries (gsl and
boost). on windows i do something like this:

imaging = Extension( 'pyag.imaging._imaging',
sources = ( glob.glob(
'Source/pyag/imaging/Src/*.cpp' ) +
glob.glob(
'Source/pyag/imaging/Src/*.h' ) ),
include_dirs = ( get_numpy_include_dirs() +
[ 'Source/pyag/imaging/Src/',
'C:/Program
Files/boost/include/boost-1_35',
'C:/Program
Files/GnuWin32/include'] ),
library_dirs = [ 'C:/Program Files/GnuWin32/lib'
],
libraries = [ 'libgsl', 'libgslcblas' ] )

obviously, the paths could vary. on unix, i need something like:

imaging = Extension( 'pyag.imaging._imaging',
sources = ( glob.glob(
'Source/pyag/imaging/Src/*.cpp' ) +
glob.glob(
'Source/pyag/imaging/Src/*.h' ) ),
include_dirs = ( get_numpy_include_dirs() +
[ 'Source/pyag/imaging/Src/' ] )
)

so my question is: what is the right way of specifying extensions
options (include_dirs, libraries, library_dirs) so that they are
portable between windows and linux? i'm thinking environment variables.
Though fairly easy to do, i was wondering if python/distutils provided
something more convenient, like searching through "common" directories,
though those aren't very standard on windows? Optimally, i would like
to have something like:

imaging = Extension( 'pyag.imaging._imaging',
sources = ( glob.glob(
'Source/pyag/imaging/Src/*.cpp' ) +
glob.glob(
'Source/pyag/imaging/Src/*.h' ) ),
include_dirs = ( get_numpy_include_dirs() +
[ 'Source/pyag/imaging/Src/' ] +
boost_include_dirs +
gsl_include_dirs ),
library_dirs = boost_library_dirs +
gsl_library_dirs,
libraries = boost_libraries + gsl_libraries )


thx for any help.

alex.

 
Reply With Quote
 
 
 
 
Robert Kern
Guest
Posts: n/a
 
      10-18-2006
Alexandre Guimond wrote:

> so my question is: what is the right way of specifying extensions
> options (include_dirs, libraries, library_dirs) so that they are
> portable between windows and linux? i'm thinking environment variables.


The user can already use command-line options and CFLAGS if he so desires, so I
wouldn't add any new environment variables.

$ CFLAGS=-I/opt/local/include python setup.py build_ext -L/opt/local/lib

> Though fairly easy to do, i was wondering if python/distutils provided
> something more convenient, like searching through "common" directories,
> though those aren't very standard on windows?


distutils wouldn't do any searching at all. Your compiler will, though.

> Optimally, i would like
> to have something like:
>
> imaging = Extension( 'pyag.imaging._imaging',
> sources = ( glob.glob(
> 'Source/pyag/imaging/Src/*.cpp' ) +
> glob.glob(
> 'Source/pyag/imaging/Src/*.h' ) ),
> include_dirs = ( get_numpy_include_dirs() +
> [ 'Source/pyag/imaging/Src/' ] +
> boost_include_dirs +
> gsl_include_dirs ),
> library_dirs = boost_library_dirs +
> gsl_library_dirs,
> libraries = boost_libraries + gsl_libraries )


That's pretty much how everyone else does it. Just make sure that
boost_{include,library}_dirs and gsl_{include,library}_dirs are defined near the
top of the file with suitable comments to draw attention to them.

However, I might suggest making a setup.cfg with something like the following
section (unindented):

# Uncomment and modify the following section to configure the locations of the
# Boost and GSL headers and libraries.

#[build_ext]
#include-dirs=/opt/local/include,/usr/local/include
#library-dirs=/opt/local/lib,/usr/local/lib

Changing data in a data file feels better to me than changing data in a program
for some reason.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

 
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
Portable Python - free portable development environment ! perica.zivkovic@gmail.com Python 7 01-13-2007 11:19 AM
portable (VHDL) vs. non-portable (altera LPM) approaches to signed computations Eli Bendersky VHDL 1 03-01-2006 02:43 PM
Writing portable libraries aaronfude@gmail.com C++ 4 07-04-2005 03:39 PM
Portable libraries for Mac/Win/Lin? Christian Decker C++ 3 10-19-2004 07:13 PM
building portable win32 extensions John Hunter Python 0 03-03-2004 07:01 PM



Advertisments