diff options
author | Zachary Zehring <zachary.zehring@canonical.com> | 2020-06-26 12:43:00 -0400 |
---|---|---|
committer | Drew Freiberger <drew.freiberger@canonical.com> | 2020-07-23 09:22:07 -0500 |
commit | 893375c5ddce74c70d99e2a1e9d3ee8fe98e27b6 (patch) | |
tree | f09e52df1db88246e082c2e78e0ad96562e600c9 | |
parent | 1ef9f20cfcdec9a97e013eff3897a85307ba3f0f (diff) |
Add try/except around pip import and reorder distro import.
This ensures python3-pip is installed as this package is missing from trusty series, which will break upgrades from older charm revisions.
-rwxr-xr-x | hooks/hooks.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/hooks/hooks.py b/hooks/hooks.py index 275a0ba..1868585 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -9,7 +9,6 @@ import collections import distutils import json import os -import pip import pprint import re import signal @@ -19,13 +18,7 @@ import sys import time try: - import distro -except ImportError: - pip.main(['install', "distro"]) - import distro - -try: - import yaml + import yaml # flake8: noqa except ImportError: if sys.version_info.major == 2: subprocess.check_call(['apt-get', 'install', '-y', 'python-yaml']) @@ -92,6 +85,18 @@ except ImportError: from pymongo import MongoClient from pymongo.errors import OperationFailure +try: + import pip # flake8: noqa +except ImportError: + apt_install('python3-pip', fatal=True) + import pip # flake8: noqa + +try: + import distro # flake8: noqa +except ImportError: + pip.main(['install', "distro"]) + import distro # flake8: noqa + from charmhelpers.contrib.charmsupport.nrpe import NRPE hooks = Hooks() |