mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-13 17:44:22 -07:00
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:
parent
5e5af458fb
commit
0624951e17
7 changed files with 117 additions and 69 deletions
|
@ -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']:
|
||||
|
|
|
@ -97,19 +97,14 @@ dest_iso:
|
|||
'''
|
||||
|
||||
import os
|
||||
import traceback
|
||||
|
||||
PYCDLIB_IMP_ERR = None
|
||||
try:
|
||||
import pycdlib
|
||||
HAS_PYCDLIB = True
|
||||
except ImportError:
|
||||
PYCDLIB_IMP_ERR = traceback.format_exc()
|
||||
HAS_PYCDLIB = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible_collections.community.general.plugins.module_utils import deps
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
with deps.declare("pycdlib"):
|
||||
import pycdlib
|
||||
|
||||
|
||||
# The upper dir exist, we only add subdirectoy
|
||||
def iso_add_dir(module, opened_iso, iso_type, dir_path):
|
||||
|
@ -306,9 +301,7 @@ def main():
|
|||
required_one_of=[('delete_files', 'add_files'), ],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
if not HAS_PYCDLIB:
|
||||
module.fail_json(
|
||||
missing_required_lib('pycdlib'), exception=PYCDLIB_IMP_ERR)
|
||||
deps.validate(module)
|
||||
|
||||
src_iso = module.params['src_iso']
|
||||
if not os.path.exists(src_iso):
|
||||
|
|
|
@ -80,25 +80,12 @@ EXAMPLES = r'''
|
|||
|
||||
RETURN = r''' # '''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
import traceback
|
||||
from os import path
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils import deps
|
||||
|
||||
try:
|
||||
from pdpyras import APISession
|
||||
HAS_PD_PY = True
|
||||
PD_IMPORT_ERR = None
|
||||
except ImportError:
|
||||
HAS_PD_PY = False
|
||||
PD_IMPORT_ERR = traceback.format_exc()
|
||||
|
||||
try:
|
||||
from pdpyras import PDClientError
|
||||
HAS_PD_CLIENT_ERR = True
|
||||
PD_CLIENT_ERR_IMPORT_ERR = None
|
||||
except ImportError:
|
||||
HAS_PD_CLIENT_ERR = False
|
||||
PD_CLIENT_ERR_IMPORT_ERR = traceback.format_exc()
|
||||
with deps.declare("pdpyras", url="https://github.com/PagerDuty/pdpyras"):
|
||||
from pdpyras import APISession, PDClientError
|
||||
|
||||
|
||||
class PagerDutyUser(object):
|
||||
|
@ -202,11 +189,7 @@ def main():
|
|||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
if not HAS_PD_PY:
|
||||
module.fail_json(msg=missing_required_lib('pdpyras', url='https://github.com/PagerDuty/pdpyras'), exception=PD_IMPORT_ERR)
|
||||
|
||||
if not HAS_PD_CLIENT_ERR:
|
||||
module.fail_json(msg=missing_required_lib('PDClientError', url='https://github.com/PagerDuty/pdpyras'), exception=PD_CLIENT_ERR_IMPORT_ERR)
|
||||
deps.validate(module)
|
||||
|
||||
access_token = module.params['access_token']
|
||||
pd_user = module.params['pd_user']
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Copyright (c) 2019, Saranya Sridharan
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = '''
|
||||
|
@ -60,18 +60,15 @@ import re
|
|||
from os.path import basename
|
||||
|
||||
from ansible.module_utils import six
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils import deps
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
try:
|
||||
with deps.declare("psutil"):
|
||||
import psutil
|
||||
|
||||
HAS_PSUTIL = True
|
||||
except ImportError:
|
||||
HAS_PSUTIL = False
|
||||
|
||||
|
||||
class PSAdapterError(Exception):
|
||||
pass
|
||||
|
@ -177,8 +174,8 @@ def compare_lower(a, b):
|
|||
|
||||
class Pids(object):
|
||||
def __init__(self, module):
|
||||
if not HAS_PSUTIL:
|
||||
module.fail_json(msg=missing_required_lib('psutil'))
|
||||
|
||||
deps.validate(module)
|
||||
|
||||
self._ps = PSAdapter.from_package(psutil)
|
||||
|
||||
|
|
|
@ -183,20 +183,14 @@ ansible_interfaces:
|
|||
'''
|
||||
|
||||
import binascii
|
||||
import traceback
|
||||
from collections import defaultdict
|
||||
from ansible_collections.community.general.plugins.module_utils import deps
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
|
||||
PYSNMP_IMP_ERR = None
|
||||
try:
|
||||
with deps.declare("pysnmp"):
|
||||
from pysnmp.entity.rfc3413.oneliner import cmdgen
|
||||
from pysnmp.proto.rfc1905 import EndOfMibView
|
||||
HAS_PYSNMP = True
|
||||
except Exception:
|
||||
PYSNMP_IMP_ERR = traceback.format_exc()
|
||||
HAS_PYSNMP = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
|
||||
|
||||
class DefineOid(object):
|
||||
|
@ -299,8 +293,7 @@ def main():
|
|||
|
||||
m_args = module.params
|
||||
|
||||
if not HAS_PYSNMP:
|
||||
module.fail_json(msg=missing_required_lib('pysnmp'), exception=PYSNMP_IMP_ERR)
|
||||
deps.validate(module)
|
||||
|
||||
cmdGen = cmdgen.CommandGenerator()
|
||||
transport_opts = dict((k, m_args[k]) for k in ('timeout', 'retries') if m_args[k] is not None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue