fix: remove deprecated distutils (#694)

This commit is contained in:
Robert Kaussow 2023-10-16 12:16:44 +02:00 committed by GitHub
parent f7592ce839
commit 0ebb855bc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 5 deletions

View File

@ -4,9 +4,9 @@ import codecs
import copy import copy
import os import os
import re import re
from distutils.version import LooseVersion
from ansible.plugins.loader import module_loader from ansible.plugins.loader import module_loader
from packaging.version import Version
from ansiblelater import LOG, utils from ansiblelater import LOG, utils
from ansiblelater.logger import flag_extra from ansiblelater.logger import flag_extra
@ -129,7 +129,7 @@ class Candidate:
f"{sid}Best practice '{description}' not met:\n{path}:{err}", f"{sid}Best practice '{description}' not met:\n{path}:{err}",
extra=flag_extra(err_labels) extra=flag_extra(err_labels)
) )
elif LooseVersion(standard.version) > LooseVersion(self.version): elif Version(standard.version) > Version(self.version):
LOG.warning( LOG.warning(
f"{sid}Future standard '{description}' not met:\n{path}:{err}", f"{sid}Future standard '{description}' not met:\n{path}:{err}",
extra=flag_extra(err_labels) extra=flag_extra(err_labels)

View File

@ -3,7 +3,6 @@
import logging import logging
import os import os
import sys import sys
from distutils.util import strtobool
import colorama import colorama
from pythonjsonlogger import jsonlogger from pythonjsonlogger import jsonlogger
@ -12,6 +11,30 @@ CONSOLE_FORMAT = "{}%(levelname)s:{} %(message)s"
JSON_FORMAT = "%(asctime)s %(levelname)s %(message)s" JSON_FORMAT = "%(asctime)s %(levelname)s %(message)s"
def strtobool(value):
"""Convert a string representation of truth to true or false."""
_map = {
"y": True,
"yes": True,
"t": True,
"true": True,
"on": True,
"1": True,
"n": False,
"no": False,
"f": False,
"false": False,
"off": False,
"0": False
}
try:
return _map[str(value).lower()]
except KeyError as err:
raise ValueError(f'"{value}" is not a valid bool value') from err
def to_bool(string): def to_bool(string):
return bool(strtobool(str(string))) return bool(strtobool(str(string)))

View File

@ -4,9 +4,9 @@ import contextlib
import re import re
import sys import sys
from contextlib import suppress from contextlib import suppress
from distutils.version import LooseVersion
import yaml import yaml
from packaging.version import Version
from ansiblelater import logger from ansiblelater import logger
@ -37,7 +37,7 @@ def count_spaces(c_string):
def standards_latest(standards): def standards_latest(standards):
return max([standard.version for standard in standards if standard.version] or ["0.1"], return max([standard.version for standard in standards if standard.version] or ["0.1"],
key=LooseVersion) key=Version)
def lines_ranges(lines_spec): def lines_ranges(lines_spec):