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.
I have module which is WHEREEVER/virtualenv/lib/pythonVERSION/site-packages/package_name.
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.
1 Answer 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')