distribute and reference static content in a python package

Discussion in 'Python' started by Vince Forgetta, Feb 2, 2012.

  1. Hi,

    I have developed a python program that contains multiple python modules
    and static content in the form of fonts (pil,pbm and tff files), html,
    images, css and javascript.

    I want to share the program with others as a python package. I have
    followed the instructions at

    http://guide.python-distribute.org/creation.html

    I have created an identical structure (apart from directory naming) as
    specified in the link, with the exception of a "static" directory within
    the module directory (towelstuff in the example). Within this directory
    are sub-directories named "css", "html", "images", "fonts" and "js".

    TowelStuff/
    bin/
    run.py
    CHANGES.txt
    docs/
    LICENSE.txt
    MANIFEST.in
    README.txt
    setup.py
    towelstuff/
    __init__.py
    module1.py
    module2.py
    static/
    images/someimage.png
    css/
    html/
    js/
    fonts/


    When the user install the program using "python setup.py install", the
    modules (in towelstuff) are copied to the common python library path
    (e.g. /usr/lib/python2.7/site-packages/), but the static content is not
    (understandably).

    What is common method to distribute static content, and how to I make
    reference to it in my python program?

    For programs in TowelStuff/bin (i.e. run.py), I currently make reference
    to the static content like so:

    sys.path[0] + "../towelstuff/static/images/someimage.png"

    I am sure there is a more pythonic way of doing this ...

    Thanks in advance for the help.

    Vince
    Vince Forgetta, Feb 2, 2012
    #1
    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. hazz
    Replies:
    6
    Views:
    49,541
    SkyUCHC
    Jun 9, 2010
  2. Matt Shomphe
    Replies:
    3
    Views:
    375
    John J. Lee
    Jul 29, 2003
  3. Replies:
    3
    Views:
    349
  4. Travis
    Replies:
    0
    Views:
    270
    Travis
    Feb 12, 2009
  5. Vinay Sajip
    Replies:
    0
    Views:
    110
    Vinay Sajip
    Jan 30, 2013
Loading...

Share This Page