1
  1. I need to package up a bunch of html/css/etc. files as a package: lets call them 'themes'. I'm doing this so I can make these available cross-application for several/any number of applications.

  2. I have module which is WHEREEVER/virtualenv/lib/pythonVERSION/site-packages/package_name.

  3. All of the 'themes' are under a folder named 'themes' in package_name

I do not need these themes importable as modules per se, I just need to have a reference to whereever they are in the filesystem and I'm not sure what the protocol would be. Can I just find that path and pass it around as I need it? I just need to find out that, whereever the package is installed, I can find a directory in that package and read what is in there.

I'm guessing, 'yes' and the answer is simple but how to go about this is not exactly clear to me at this point, or if there is a better way I'm unaware of. Any input appreciated.

Some background:

I'm trying to create a module loader for flask-fleem:

https://github.com/thrisp/fleem

EDIT:

The answer that worked for me for now was to just export a constant from the package init file:

PACKAGE_THEMES = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'themes')

improvements and/or better solutions appreciated.

asked May 6, 2013 at 17:01

1 Answer 1

1

If you can import package_name, then you can determine the directory where the package is installed (package_dir), and therefore also where the themes directory is.

import os
import package_name
package_dir = os.path.dirname(package_name.__file__)
theme_dir = os.path.join(package_dir, 'themes')
answered May 6, 2013 at 17:37
Sign up to request clarification or add additional context in comments.

1 Comment

I just came to note the answer I came up with, very similar to this.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.