Application Packages

Discussion in 'Python' started by Dj Gilcrease, Sep 15, 2009.

  1. Dj Gilcrease

    Dj Gilcrease Guest

    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
    Dj Gilcrease, Sep 15, 2009
    #1
    1. Advertising

  2. 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
    Diez B. Roggisch, Sep 15, 2009
    #2
    1. Advertising

  3. Dj Gilcrease

    Dj Gilcrease Guest

    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
    Dj Gilcrease, Sep 16, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sandeep

    VHDL Packages

    Sandeep, Aug 13, 2003, in forum: VHDL
    Replies:
    1
    Views:
    5,185
    Egbert Molenkamp
    Aug 14, 2003
  2. Lolo
    Replies:
    3
    Views:
    593
  3. Paul  Smith
    Replies:
    0
    Views:
    729
    Paul Smith
    Nov 18, 2003
  4. David Lyon
    Replies:
    19
    Views:
    573
    David Lyon
    Apr 24, 2009
  5. Ian
    Replies:
    3
    Views:
    167
Loading...

Share This Page