Re: Extensions on Linux: import without underscore?

2005-06-20 Thread Kent Johnson
Terry Hancock wrote:
 Okay, you may want a more elegant way to do this and other people
 have already responded to that point, but you do at least know you
 can just give it a new name:
 
 import _bright
 bright = _bright

or more idiomatically and without adding _bright to the namespace:
import _bright as bright

Kent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extensions on Linux: import without underscore?

2005-06-20 Thread James Carroll
Swig actually was generating a bright.py file, but scons was leaving
it in the source directory instead of putting it next to my
SharedLibrary().  Once I moved the bright.py next to the _bright.so,
it all worked with just import bright.  Thanks everyone.

My next trick is to try the same thing with distutils, and see how it
compares with SCons.

-Jim

On 6/20/05, Kent Johnson [EMAIL PROTECTED] wrote:
 Terry Hancock wrote:
  Okay, you may want a more elegant way to do this and other people
  have already responded to that point, but you do at least know you
  can just give it a new name:
 
  import _bright
  bright = _bright
 
 or more idiomatically and without adding _bright to the namespace:
 import _bright as bright
 
 Kent
 --
 http://mail.python.org/mailman/listinfo/python-list
 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extensions on Linux: import without underscore?

2005-06-19 Thread Terry Hancock
On Saturday 18 June 2005 10:35 pm, James Carroll wrote:
 Hi, I'm creating an extension called _bright.so on linux.  I can
 import it with import _bright, but how can I import bright and get the
 package?
 
 On windows, I've been able to import bright instead of import _bright,
 but on Linux it seems to need the underscore.  I'm tempted to create a
 bright.py with from _bright import *, but I'm wondering if there's a
 more direct way.

Okay, you may want a more elegant way to do this and other people
have already responded to that point, but you do at least know you
can just give it a new name:

import _bright
bright = _bright

right?

You can attach a new name to any Python object trivially (this is
akin to a pointer assignment in C, it does not copy any significant
amount of data).

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Extensions on Linux: import without underscore?

2005-06-18 Thread James Carroll
Hi, I'm creating an extension called _bright.so on linux.  I can
import it with import _bright, but how can I import bright and get the
package?

On windows, I've been able to import bright instead of import _bright,
but on Linux it seems to need the underscore.  I'm tempted to create a
bright.py with from _bright import *, but I'm wondering if there's a
more direct way.

Also, I'm using scons to generate my lib, and it insists on prepending
the characters lib to my library name, so if I tell it to generate
_bright.so it gives me lib_bright.so.  Is there a way of turning this
off so I don't have to rename it back to _bright.so?

Thanks,
-Jim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extensions on Linux: import without underscore?

2005-06-18 Thread Robert Kern
James Carroll wrote:
 Hi, I'm creating an extension called _bright.so on linux.  I can
 import it with import _bright, but how can I import bright and get the
 package?
 
 On windows, I've been able to import bright instead of import _bright,

That has to be a bug. You shouldn't rely on that behavior.

 but on Linux it seems to need the underscore.  I'm tempted to create a
 bright.py with from _bright import *, but I'm wondering if there's a
 more direct way.

Call it bright.so .

 Also, I'm using scons to generate my lib, and it insists on prepending
 the characters lib to my library name, so if I tell it to generate
 _bright.so it gives me lib_bright.so.  Is there a way of turning this
 off so I don't have to rename it back to _bright.so?

If at all possible, you should use distutils to build Python extensions.

If you must use Scons, read

   http://www.scons.org/cgi-bin/wiki/PythonExtensions

and use

SharedLibrary(...
   SHLIBPREFIX=,
   ...)

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die.
   -- Richard Harter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extensions on Linux: import without underscore?

2005-06-18 Thread jchiang
Try

SharedLibrary(bright.so, SHLIBPREFIX=, ...)

The prefix option is documented here

http://www.scons.org/doc/HTML/scons-man.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extensions on Linux: import without underscore?

2005-06-18 Thread James Carroll
Thanks Robert.

 
 Call it bright.so .
 

If I rename it bright.so, then I get the error:
  ImportError: dynamic module does not define init function (initbright)

I'm using swig with the module declaration
  %module bright

I've looked at some other source, and it looks like there are some
good reasons to have a bright.py that passes calls on to _bright.

 If at all possible, you should use distutils to build Python extensions.

 Where can I find similar distutils C++ examples?  Can it do most of
what Scons does?

 
 If you must use Scons, read
 
http://www.scons.org/cgi-bin/wiki/PythonExtensions
 

Very nice, strange that didn't show up for all my googles of scons
python, etc.  I like how it uses distutils to get flags...  I'm
extending wxPython, so I'm using the wxWidgets 
env.ParseConfig('wx-config --cppflags --libs')   Technique... I'll
have to ponder using one or the other or both.  Hmm

-Jim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extensions on Linux: import without underscore?

2005-06-18 Thread Robert Kern
James Carroll wrote:
 Thanks Robert.
 
Call it bright.so .
 
 If I rename it bright.so, then I get the error:
   ImportError: dynamic module does not define init function (initbright)

Sorry, I should have been clearer. Just renaming the file won't help. 
The init function also needs to be appropriately named.

 I'm using swig with the module declaration
   %module bright
 
 I've looked at some other source, and it looks like there are some
 good reasons to have a bright.py that passes calls on to _bright.

Reread the SWIG documentation. If it is going to prepend an underscore 
to the extension name, it is usually also generating the appropriate 
bright.py . I suspect that this is why it worked on Windows but didn't 
work when you moved to Linux.

If at all possible, you should use distutils to build Python extensions.
 
  Where can I find similar distutils C++ examples?  Can it do most of
 what Scons does?

Even better, it will handle running SWIG, too. wxPython itself is an 
example, and one that you most certainly should emulate.

If you must use Scons, read

   http://www.scons.org/cgi-bin/wiki/PythonExtensions
 
 Very nice, strange that didn't show up for all my googles of scons
 python, etc.  I like how it uses distutils to get flags...  I'm
 extending wxPython, so I'm using the wxWidgets 
 env.ParseConfig('wx-config --cppflags --libs')   Technique... I'll
 have to ponder using one or the other or both.  Hmm

If you're extending wxPython, cannibalize wxPython's build procedure. 
Any other way, there madness lies.

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die.
   -- Richard Harter

-- 
http://mail.python.org/mailman/listinfo/python-list