Application Packages

D

Dj Gilcrease

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
 
D

Diez B. Roggisch

Dj said:
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
 
D

Dj Gilcrease

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top