Prepare for distutils.version being removed in Python 3.12 (#3936) (#3942)

* Prepare for distutils.version being removed in Python 2.12.

* Fix copy'n'paste error.

* Re-add Loose prefix.

* Fix Python version typos.

* Improve formulation.

* Move message into own line.

* Fix casing, now that the object is no longer called Version.

(cherry picked from commit a2f72be6c8)
This commit is contained in:
Felix Fontein 2021-12-24 19:15:51 +01:00 committed by GitHub
commit e02568d28a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 102 additions and 59 deletions

View file

@ -152,11 +152,11 @@ stdout:
sample: "org.gnome.Calendar/x86_64/stable\tcurrent\norg.gnome.gitg/x86_64/stable\tcurrent\n"
'''
from distutils.version import StrictVersion
from ansible.module_utils.six.moves.urllib.parse import urlparse
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
OUTDATED_FLATPAK_VERSION_ERROR_MESSAGE = "Unknown option --columns=application"
@ -172,7 +172,7 @@ def install_flat(module, binary, remote, names, method, no_dependencies):
id_names.append(name)
base_command = [binary, "install", "--{0}".format(method)]
flatpak_version = _flatpak_version(module, binary)
if StrictVersion(flatpak_version) < StrictVersion('1.1.3'):
if LooseVersion(flatpak_version) < LooseVersion('1.1.3'):
base_command += ["-y"]
else:
base_command += ["--noninteractive"]
@ -196,7 +196,7 @@ def uninstall_flat(module, binary, names, method):
]
command = [binary, "uninstall"]
flatpak_version = _flatpak_version(module, binary)
if StrictVersion(flatpak_version) < StrictVersion('1.1.3'):
if LooseVersion(flatpak_version) < LooseVersion('1.1.3'):
command += ["-y"]
else:
command += ["--noninteractive"]

View file

@ -140,7 +140,8 @@ EXAMPLES = '''
import os
import re
import tempfile
from distutils import version
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
from ansible.module_utils.common.text.converters import to_bytes
from ansible.module_utils.basic import AnsibleModule
@ -493,7 +494,7 @@ class HomebrewCask(object):
def _brew_cask_command_is_deprecated(self):
# The `brew cask` replacements were fully available in 2.6.0 (https://brew.sh/2020/12/01/homebrew-2.6.0/)
return version.LooseVersion(self._get_brew_version()) >= version.LooseVersion('2.6.0')
return LooseVersion(self._get_brew_version()) >= LooseVersion('2.6.0')
# /checks ------------------------------------------------------ }}}
# commands ----------------------------------------------------- {{{

View file

@ -97,9 +97,10 @@ RETURN = r''' # '''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
from distutils.version import StrictVersion
import os
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
class Mas(object):
@ -145,7 +146,7 @@ class Mas(object):
# Is the version recent enough?
rc, out, err = self.run(['version'])
if rc != 0 or not out.strip() or StrictVersion(out.strip()) < StrictVersion('1.5.0'):
if rc != 0 or not out.strip() or LooseVersion(out.strip()) < LooseVersion('1.5.0'):
self.module.fail_json(msg='`mas` tool in version 1.5.0+ needed, got ' + out.strip())
def check_signin(self):

View file

@ -135,10 +135,10 @@ import re
import shlex
import sqlite3
from distutils.version import StrictVersion
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
# Function used for executing commands.
def execute_command(cmd, module):
@ -435,7 +435,7 @@ def parse_package_name(names, pkg_spec, module):
if pkg_spec[name]['branch']:
branch_release = "6.0"
if StrictVersion(platform.release()) < StrictVersion(branch_release):
if LooseVersion(platform.release()) < LooseVersion(branch_release):
module.fail_json(msg="package name using 'branch' syntax requires at least OpenBSD %s: %s" % (branch_release, name))
# Sanity check that there are no trailing dashes in flavor.

View file

@ -133,8 +133,6 @@ except ImportError:
XML_IMP_ERR = traceback.format_exc()
HAS_XML = False
from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.urls import fetch_url
@ -142,6 +140,8 @@ from ansible.module_utils.common.text.converters import to_text
from ansible.module_utils.six.moves import configparser, StringIO
from io import open
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
REPO_OPTS = ['alias', 'name', 'priority', 'enabled', 'autorefresh', 'gpgcheck']