Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Application Packages

Reply
Thread Tools

Application Packages

 
 
Dj Gilcrease
Guest
Posts: n/a
 
      09-15-2009
Say I have an application that lives in /usr/local/myapp it comes with
some default plugins that live in /usr/local/myapp/plugins and I allow
users to have plugins that would live in ~/myapp/plugins

Is there a way to map ~/myapp to a user package so I could do "from
user.plugins import *" or better yet map it to myapp.user?


Dj Gilcrease
OpenRPG Developer
~~http://www.openrpg.com
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      09-15-2009
Dj Gilcrease schrieb:
> Say I have an application that lives in /usr/local/myapp it comes with
> some default plugins that live in /usr/local/myapp/plugins and I allow
> users to have plugins that would live in ~/myapp/plugins
>
> Is there a way to map ~/myapp to a user package so I could do "from
> user.plugins import *" or better yet map it to myapp.user?


No. You can execfile things in there, or you can add ~/myapp to the
sys.path and then import things in there. And you can create aliases for
those of course.

Alternatively, namespace-packages and virtualenvs might be a solution,
but not exactly straight-forward as well.

Diez
 
Reply With Quote
 
 
 
 
Dj Gilcrease
Guest
Posts: n/a
 
      09-16-2009
when looking up namespace-packages I found pkgutil which lets me add a
myapp.user package with the following in its __init__.py and nothing
else

import os, os.path

from pkgutil import extend_path
homedir = os.environ.get('HOME') or os.environ.get('USERPROFILE')
__path__ = extend_path([os.path.abspath(homedir + os.sep + 'myapp')], __name__)



now I can do "from myapp.user.plugins import *" and it works
 
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
Python Packages : A loomingproblem? packages might no longer work? (well not on your platform or python version anyway) David Lyon Python 19 04-23-2009 11:10 PM
Advice on converting hashed packages to pseudo-hashed packages Ian Perl Misc 3 02-12-2005 12:17 AM
Do the javax.imageio packages replace packages in com.sun.image? Paul Smith Java 0 11-18-2003 02:58 PM
VHDL Packages Sandeep VHDL 1 08-14-2003 08:00 AM



Advertisments