~evarlast/charms/trusty/mongodb/fix-backup

« back to all changes in this revision

Viewing changes to charmhelpers/contrib/python/packages.py

  • Committer: Ryan Beisner
  • Date: 2016-06-10 11:42:00 UTC
  • mfrom: (87.1.1 mongodb)
  • Revision ID: ryan.beisner@canonical.com-20160610114200-ty38q7uc1kkxwkyq
[james-page, r=1chb1n] Resync charm-helpers to ensure that charm understands the Newton UCA.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import os
21
21
import subprocess
 
22
import sys
22
23
 
23
24
from charmhelpers.fetch import apt_install, apt_update
24
25
from charmhelpers.core.hookenv import charm_dir, log
25
26
 
26
 
try:
27
 
    from pip import main as pip_execute
28
 
except ImportError:
29
 
    apt_update()
30
 
    apt_install('python-pip')
31
 
    from pip import main as pip_execute
32
 
 
33
27
__author__ = "Jorge Niedbalski <jorge.niedbalski@canonical.com>"
34
28
 
35
29
 
 
30
def pip_execute(*args, **kwargs):
 
31
    """Overriden pip_execute() to stop sys.path being changed.
 
32
 
 
33
    The act of importing main from the pip module seems to cause add wheels
 
34
    from the /usr/share/python-wheels which are installed by various tools.
 
35
    This function ensures that sys.path remains the same after the call is
 
36
    executed.
 
37
    """
 
38
    try:
 
39
        _path = sys.path
 
40
        try:
 
41
            from pip import main as _pip_execute
 
42
        except ImportError:
 
43
            apt_update()
 
44
            apt_install('python-pip')
 
45
            from pip import main as _pip_execute
 
46
        _pip_execute(*args, **kwargs)
 
47
    finally:
 
48
        sys.path = _path
 
49
 
 
50
 
36
51
def parse_options(given, available):
37
52
    """Given a set of options, check if available"""
38
53
    for key, value in sorted(given.items()):