Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: "python exe" and "py plugins"

Reply
Thread Tools

RE: "python exe" and "py plugins"

 
 
Marc Boeren
Guest
Posts: n/a
 
      11-18-2003

> and it works WITHOUT THE PYTHON RUNTIME INSTALLED ...
> sure that this script can't import lib which are not in the exe


If I remember correctly py2exe provides the python23.dll, so there's your
runtime... meaning that you can probably import whatever library you wish in
your plugin.
You can probably also dynamically import your plugin instead of using
execfile.

Cheerio, Marc.

 
Reply With Quote
 
 
 
 
marco
Guest
Posts: n/a
 
      11-19-2003
great ! it works with dynamic import ( __import__() )!
it's a lot better than an execfile ...

"Marc Boeren" <(E-Mail Removed)> a écrit dans le message de news:
http://www.velocityreviews.com/forums/(E-Mail Removed)...
>
> > and it works WITHOUT THE PYTHON RUNTIME INSTALLED ...
> > sure that this script can't import lib which are not in the exe

>
> If I remember correctly py2exe provides the python23.dll, so there's your
> runtime... meaning that you can probably import whatever library you wish

in
> your plugin.
> You can probably also dynamically import your plugin instead of using
> execfile.
>
> Cheerio, Marc.
>



 
Reply With Quote
 
 
 
 
Ahmad Baitalmal
Guest
Posts: n/a
 
      11-19-2003
marco wrote:
> great ! it works with dynamic import ( __import__() )!
> it's a lot better than an execfile ...
>
> "Marc Boeren" <(E-Mail Removed)> a écrit dans le message de news:
> (E-Mail Removed)...


I'm a bit lost, I'm trying to do the same thing withe BitLeaf
(www.bitbuilder.com/bitleaf).
I put all my pulgins in a folder named "services", then when the
application loads it looks in that folder for any subfolders that have
__init__.py in them (packages, that's how I plan to distribute the plugins).

That works fine in linux or uncompiled on windows, but with py2exe, it
can't find the "services" folder.

My question is, should I keep going down that road or is there a
"correct" way of handling plugins in python that I'm not aware of?

Thx



 
Reply With Quote
 
Thomas Heller
Guest
Posts: n/a
 
      11-19-2003
Ahmad Baitalmal <(E-Mail Removed)> writes:

> marco wrote:
>> great ! it works with dynamic import ( __import__() )!
>> it's a lot better than an execfile ...
>> "Marc Boeren" <(E-Mail Removed)> a écrit dans le message de news:
>> (E-Mail Removed)...

>
> I'm a bit lost, I'm trying to do the same thing withe BitLeaf
> (www.bitbuilder.com/bitleaf).
> I put all my pulgins in a folder named "services", then when the
> application loads it looks in that folder for any subfolders that have
> __init__.py in them (packages, that's how I plan to distribute the
> plugins).
>
> That works fine in linux or uncompiled on windows, but with py2exe, it
> can't find the "services" folder.


You should be a bit more specific here - what do you mean by "it can't
find the services folder" ?

I can only think of two problems - first you should locate the folder in
the file system (probably relative to the exe-file, which is
sys.executable), and then you should add it to sys.path.
Second, you must make sure that py2exe doesn't include this folder.

Thomas
 
Reply With Quote
 
Ahmad Baitalmal
Guest
Posts: n/a
 
      11-20-2003
Thomas Heller wrote:
>>That works fine in linux or uncompiled on windows, but with py2exe, it
>>can't find the "services" folder.

>
>
> You should be a bit more specific here - what do you mean by "it can't
> find the services folder" ?
>

I figured out that's what is happening. py2exe used to package my
"services" package because it was imported normally. But now I do a
folder lookup to find all subfolders in my sys.executable + '/services'
folder and
exec("import %s" % foldername )
each subfolder. That's why py2exe can't package those packages when its
building.

And I'm doing it that way because the set of plugins are not known
ofcourse, that's why I do this dynamic discovery at runtime.


This will work, but it feels a bit patchy to me, is there a way in
python to say "here is the path to folder x, recursevily import all
packages you find in there"? py, pyc, pyd also?

Thx,
ahmadster



 
Reply With Quote
 
Thomas Heller
Guest
Posts: n/a
 
      11-20-2003
Ahmad Baitalmal <(E-Mail Removed)> writes:

> Thomas Heller wrote:
>>>That works fine in linux or uncompiled on windows, but with py2exe, it
>>>can't find the "services" folder.

>> You should be a bit more specific here - what do you mean by "it
>> can't
>> find the services folder" ?
>>

> I figured out that's what is happening. py2exe used to package my
> "services" package because it was imported normally. But now I do a
> folder lookup to find all subfolders in my sys.executable +
> '/services' folder and
> exec("import %s" % foldername )
> each subfolder. That's why py2exe can't package those packages when
> its building.
>
> And I'm doing it that way because the set of plugins are not known
> ofcourse, that's why I do this dynamic discovery at runtime.
>
>
> This will work, but it feels a bit patchy to me, is there a way in
> python to say "here is the path to folder x, recursevily import all
> packages you find in there"? py, pyc, pyd also?


No, but it's easy to do that yourself.

Thomas
 
Reply With Quote
 
Thomas Heller
Guest
Posts: n/a
 
      11-20-2003
Thomas Heller <(E-Mail Removed)> writes:

> Ahmad Baitalmal <(E-Mail Removed)> writes:
>
>> Thomas Heller wrote:
>>>>That works fine in linux or uncompiled on windows, but with py2exe, it
>>>>can't find the "services" folder.
>>> You should be a bit more specific here - what do you mean by "it
>>> can't
>>> find the services folder" ?
>>>

>> I figured out that's what is happening. py2exe used to package my
>> "services" package because it was imported normally. But now I do a
>> folder lookup to find all subfolders in my sys.executable +
>> '/services' folder and
>> exec("import %s" % foldername )
>> each subfolder. That's why py2exe can't package those packages when
>> its building.
>>
>> And I'm doing it that way because the set of plugins are not known
>> ofcourse, that's why I do this dynamic discovery at runtime.
>>
>>
>> This will work, but it feels a bit patchy to me, is there a way in
>> python to say "here is the path to folder x, recursevily import all
>> packages you find in there"? py, pyc, pyd also?

>
> No, but it's easy to do that yourself.


That wasn't a good answer, you already discovered that.

But, you may want to organize your plugins somewhat differently.
Maybe you can create a plugin package (a directory plugin, which
contains an __init__.py file). And then you (or your users) write the
plugins as modules contained in this directory. Or someting like that.

It may be useful to look into sources which do something like this, PIL
comes to mind, but there are most certainly more.

Thomas
 
Reply With Quote
 
Ahmad Baitalmal
Guest
Posts: n/a
 
      11-20-2003
Thomas Heller wrote:
> It may be useful to look into sources which do something like this, PIL
> comes to mind, but there are most certainly more.
>
> Thomas


Cool, thanks
ahmadster



 
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
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM



Advertisments