1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

pip: produce better error msg on import error (#47743)

* pip: produce better error msg on import error

* Added porting guide entry for 2.7
This commit is contained in:
Jordan Borean 2018-11-01 00:30:37 +10:00 committed by Martin Krizek
parent f536944e3a
commit 73141d5035
2 changed files with 10 additions and 2 deletions

View file

@ -221,6 +221,10 @@ Noteworthy module changes
#> ansible -m include_role -a 'name=myrole' all
* The ``pip`` module has added a dependency on ``setuptools`` to support version requirements, this requirement is for
the Python interpreter that executes the module and not the Python interpreter that the module is managing.
Plugins
=======

View file

@ -241,16 +241,19 @@ import sys
import tempfile
import operator
import shlex
import traceback
from distutils.version import LooseVersion
SETUPTOOLS_IMP_ERR = None
try:
from pkg_resources import Requirement
HAS_SETUPTOOLS = True
except ImportError:
HAS_SETUPTOOLS = False
SETUPTOOLS_IMP_ERR = traceback.format_exc()
from ansible.module_utils.basic import AnsibleModule, is_executable
from ansible.module_utils.basic import AnsibleModule, is_executable, missing_required_lib
from ansible.module_utils._text import to_native
from ansible.module_utils.six import PY3
@ -573,7 +576,8 @@ def main():
)
if not HAS_SETUPTOOLS:
module.fail_json(msg="No setuptools found in remote host, please install it first.")
module.fail_json(msg=missing_required_lib("setuptools"),
exception=SETUPTOOLS_IMP_ERR)
state = module.params['state']
name = module.params['name']