add dependency manager (#5535)

* add dependency manager

* add plugins/module_utils/deps.py to BOTMETA

* ditch usng OrderedDict to keep compatibility with Python 2.6

* Update plugins/module_utils/deps.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2022-11-17 18:55:00 +13:00 committed by GitHub
parent 5e5af458fb
commit 0624951e17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 117 additions and 69 deletions

View file

@ -230,18 +230,11 @@ dnsimple_record_info:
type: str
'''
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import missing_required_lib
from ansible_collections.community.general.plugins.module_utils import deps
try:
with deps.declare("requests"):
from requests import Request, Session
except ImportError:
HAS_REQUESTS = False
REQUESTS_IMPORT_ERROR = traceback.format_exc()
else:
HAS_REQUESTS = True
REQUESTS_IMPORT_ERROR = None
def build_url(account, key, is_sandbox):
@ -310,10 +303,7 @@ def main():
params['api_key'],
params['sandbox'])
if not HAS_REQUESTS:
module.exit_json(
msg=missing_required_lib('requests'),
exception=REQUESTS_IMPORT_ERROR)
deps.validate(module)
# At minimum we need account and key
if params['account_id'] and params['api_key']: