Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for distutils.version being removed in Python 3.12 #597

Merged
merged 3 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelogs/fragments/597-prepare-distutils.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

minor_changes:
- all modules - prepare for deprecation of distutils LooseVersion.

bugfixes:
- ZapiWrapper (module_utils) - fix only partial zabbix version is returned.
1 change: 1 addition & 0 deletions plugins/module_utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from __future__ import absolute_import, division, print_function
__metaclass__ = type

from ansible.module_utils.basic import env_fallback


Expand Down
21 changes: 21 additions & 0 deletions plugins/module_utils/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-

# Copyright: (c) 2021, Felix Fontein <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

"""Provide version object to compare version numbers."""

from __future__ import absolute_import, division, print_function
__metaclass__ = type

from ansible.module_utils.six import raise_from

try:
from ansible.module_utils.compat.version import LooseVersion
except ImportError:
try:
from distutils.version import LooseVersion
except ImportError as exc:
msg = ('To use this plugin or module with ansible-core < 2.11, '
'you need to use Python < 3.12 with distutils.version present')
raise_from(ImportError(msg), exc)
2 changes: 1 addition & 1 deletion plugins/module_utils/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, module, zbx=None):

self.login()

self._zbx_api_version = self._zapi.api_version()[:5]
self._zbx_api_version = self._zapi.api_version()

def login(self):
# check if api already logged in
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/zabbix_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,12 @@
'''


from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
from ansible_collections.community.zabbix.plugins.module_utils.wrappers import ZapiWrapper
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion

import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/zabbix_discovery_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@
'''


from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion

import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/zabbix_globalmacro.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@

RETURN = r"""
"""
from distutils.version import LooseVersion


from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion

import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/zabbix_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,11 @@

import copy

from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion

import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/zabbix_hostmacro.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@
'''


from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion

import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/zabbix_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@

from io import BytesIO
from operator import itemgetter
from distutils.version import LooseVersion

from ansible.module_utils.basic import AnsibleModule, missing_required_lib

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion

import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/zabbix_mediatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,11 @@
'''


from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion

import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/zabbix_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@
RETURN = r''' # '''


from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion

import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/zabbix_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,13 @@
import re
import xml.etree.ElementTree as ET

from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils.six import PY2

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion

import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/zabbix_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,12 @@

import copy

from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
from ansible_collections.community.zabbix.plugins.module_utils.helpers import helper_normalize_data
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion

import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


Expand Down
2 changes: 1 addition & 1 deletion tests/sanity/ignore-2.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ plugins/doc_fragments/zabbix.py metaclass-boilerplate
roles/zabbix_agent/molecule/with-server/tests/test_agent.py future-import-boilerplate
roles/zabbix_agent/molecule/with-server/tests/test_default.py future-import-boilerplate
roles/zabbix_agent/molecule/with-server/tests/test_agent.py metaclass-boilerplate
roles/zabbix_agent/molecule/with-server/tests/test_default.py metaclass-boilerplate
roles/zabbix_agent/molecule/with-server/tests/test_default.py metaclass-boilerplate
2 changes: 1 addition & 1 deletion tests/sanity/ignore-2.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ plugins/doc_fragments/zabbix.py metaclass-boilerplate
roles/zabbix_agent/molecule/with-server/tests/test_agent.py future-import-boilerplate
roles/zabbix_agent/molecule/with-server/tests/test_default.py future-import-boilerplate
roles/zabbix_agent/molecule/with-server/tests/test_agent.py metaclass-boilerplate
roles/zabbix_agent/molecule/with-server/tests/test_default.py metaclass-boilerplate
roles/zabbix_agent/molecule/with-server/tests/test_default.py metaclass-boilerplate
2 changes: 1 addition & 1 deletion tests/sanity/ignore-2.12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ plugins/modules/zabbix_mediatype.py validate-modules:parameter-list-no-elements
plugins/modules/zabbix_template.py validate-modules:doc-elements-mismatch
plugins/modules/zabbix_template.py validate-modules:parameter-list-no-elements
plugins/modules/zabbix_user.py validate-modules:doc-elements-mismatch
plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements
plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements
2 changes: 1 addition & 1 deletion tests/sanity/ignore-2.13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ plugins/modules/zabbix_mediatype.py validate-modules:parameter-list-no-elements
plugins/modules/zabbix_template.py validate-modules:doc-elements-mismatch
plugins/modules/zabbix_template.py validate-modules:parameter-list-no-elements
plugins/modules/zabbix_user.py validate-modules:doc-elements-mismatch
plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements
plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements
2 changes: 1 addition & 1 deletion tests/sanity/ignore-2.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ plugins/modules/zabbix_template.py validate-modules:parameter-list-no-elements
plugins/modules/zabbix_user.py validate-modules:doc-elements-mismatch
plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements
plugins/doc_fragments/zabbix.py future-import-boilerplate
plugins/doc_fragments/zabbix.py metaclass-boilerplate
plugins/doc_fragments/zabbix.py metaclass-boilerplate
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ commands =
antsibull-changelog lint

[flake8]
# E123, E125 skipped as they are invalid PEP-8.
per-file-ignores =
plugins/module_utils/version.py: F401

show-source = True
ignore = E123,E125,E402,E501,E741,W503
Expand Down