Merge lp:~ajkavanagh/charm-helpers/fix-path-mangling-lp1540299 into lp:charm-helpers

Proposed by Alex Kavanagh
Status: Merged
Merged at revision: 526
Proposed branch: lp:~ajkavanagh/charm-helpers/fix-path-mangling-lp1540299
Merge into: lp:charm-helpers
Diff against target: 46 lines (+22/-7)
1 file modified
charmhelpers/contrib/python/packages.py (+22/-7)
To merge this branch: bzr merge lp:~ajkavanagh/charm-helpers/fix-path-mangling-lp1540299
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+284737@code.launchpad.net

Description of the change

Mod to charmhelpers.contrib.python.packages to stop importing pip from adding wheels to the path when it is included as an import in another file. This is to prevent the side-effect of unintentionally including an updated module over an expected system package. The pip_execute() command still causes the path/wheels to be included for the duration of the pip_execute() command only (the path is restored after the pip_execute()) finishes.

To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

Approved, thanks for the fix

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/python/packages.py'
--- charmhelpers/contrib/python/packages.py 2015-11-03 19:40:58 +0000
+++ charmhelpers/contrib/python/packages.py 2016-02-02 13:51:49 +0000
@@ -19,20 +19,35 @@
1919
20import os20import os
21import subprocess21import subprocess
22import sys
2223
23from charmhelpers.fetch import apt_install, apt_update24from charmhelpers.fetch import apt_install, apt_update
24from charmhelpers.core.hookenv import charm_dir, log25from charmhelpers.core.hookenv import charm_dir, log
2526
26try:
27 from pip import main as pip_execute
28except ImportError:
29 apt_update()
30 apt_install('python-pip')
31 from pip import main as pip_execute
32
33__author__ = "Jorge Niedbalski <jorge.niedbalski@canonical.com>"27__author__ = "Jorge Niedbalski <jorge.niedbalski@canonical.com>"
3428
3529
30def 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
36def parse_options(given, available):51def parse_options(given, available):
37 """Given a set of options, check if available"""52 """Given a set of options, check if available"""
38 for key, value in sorted(given.items()):53 for key, value in sorted(given.items()):

Subscribers

People subscribed via source and target branches