canonical / canonical/layer-basic

use_venv breaks charmhelpers.contrib.python.pip_install

Open
#132 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
10
Forks
42
PR merge metrics
No merged PRs in 30d

Description

Per the layer-basic docs, `wheelhouse.txt` is intended only for **charm** dependencies. Payload dependencies should be installed separately.

For installing Python packages, this has traditionally been accomplished via `charmhelpers.contrib.python.pip_install`. The default use of venv has created a side-effect that breaks this pattern.

Internally, [pip_install](https://github.com/juju/charm-helpers/blob/master/charmhelpers/contrib/python/packages.py#L29) import's pip and execute's it's main:

```python
def pip_execute(*args, **kwargs):
[...]
try:
_path = sys.path
try:
from pip import main as _pip_execute
except ImportError:
apt_update()
if six.PY2:
apt_install('python-pip')
else:
apt_install('python3-pip')
from pip import main as _pip_execute
_pip_execute(*args, **kwargs)
finally:
sys.path = _path
```

This will use the pip installed inside the venv, installing the package(s) there rather than to the system and the payload will fail due to missing dependencies.

I'm not sure if we want to patch charmhelpers.contrib.python, if it's feasible to do something within layer:basic, or if we should instead create a new layer in the spirit of layer:apt to install packages in a way that's fully compatible with a charm-centric venv.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.