As a chef user I thought I would give this a try. Docs are not clear. Any other framework I would have given up but I will give one more shot. This framework is not critical my any stretch of the imagination so unless docs are cleaned up I dont expect wide adoption esp for python devs.
That being said…
I can build a plan and export. I ssh into the container to find my pip install libs. Guess what they are nowhere to be found despite the below. So how do I do a simple pip install?
It looks like you’re installing your pip deps into the global python installation, which lives in the core/python package. When you export, you’re using a clean version of core/python without these added packages. That’s obviously not what you’re going for.
Consider using a virtual environment. Virtual envs are generally best practice no matter where/how you’re deploying Python. I’m building Python services and CLI tools with Habitat without any issue. Here’s roughly how I do it:
For services:
do_install() {
mkdir -p $pkg_prefix
# copy all service files into $pkg_prefix (usually from $PLAN_CONTEXT/..)
cd $pkg_prefix
python -m venv venv
source ./venv/bin/activate
pip install -r path/to/requirements.txt
}
In the service’s init hook, symlink all the service files and venv folder into the service’s var directory, {{pkg.svc_var_path}}. In the run hook, cd into the service’s var directory, source env/bin/activate, and start your service as you normally would.
For CLI tools:
pkg_bin_dirs=(bin)
do_install() {
cd $pkg_prefix
python -m venv .
source ./bin/activate
pip install "${PLAN_CONTEXT}/.."
# where the habitat directory is in the top level of the python package, next to setup.py
}
If you have shell entrypoints configured in your package, the binstubs will be put in $pkg_prefix/bin, which makes it easy to binlink globally or hab pkg exec.
Note: the venv module is only included by default in Python 3. You may need to do some legwork to get this working with core/python2
Be aware also you may sometimes need to append your package’s path to the PYTHONPATH environment variable. You can do that like this in your plan.sh as needed: