Replace LooseVersion with AwesomeVersion (#46330)

This commit is contained in:
Joakim Sørensen 2021-02-10 15:26:38 +01:00 committed by GitHub
parent ea4ad85488
commit dbb98e6cac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,5 @@
"""Module to help with parsing and generating configuration files.""" """Module to help with parsing and generating configuration files."""
from collections import OrderedDict from collections import OrderedDict
from distutils.version import LooseVersion # pylint: disable=import-error
import logging import logging
import os import os
import re import re
@ -8,6 +7,7 @@ import shutil
from types import ModuleType from types import ModuleType
from typing import Any, Callable, Dict, Optional, Sequence, Set, Tuple, Union from typing import Any, Callable, Dict, Optional, Sequence, Set, Tuple, Union
from awesomeversion import AwesomeVersion
import voluptuous as vol import voluptuous as vol
from voluptuous.humanize import humanize_error from voluptuous.humanize import humanize_error
@ -364,15 +364,15 @@ def process_ha_config_upgrade(hass: HomeAssistant) -> None:
"Upgrading configuration directory from %s to %s", conf_version, __version__ "Upgrading configuration directory from %s to %s", conf_version, __version__
) )
version_obj = LooseVersion(conf_version) version_obj = AwesomeVersion(conf_version)
if version_obj < LooseVersion("0.50"): if version_obj < AwesomeVersion("0.50"):
# 0.50 introduced persistent deps dir. # 0.50 introduced persistent deps dir.
lib_path = hass.config.path("deps") lib_path = hass.config.path("deps")
if os.path.isdir(lib_path): if os.path.isdir(lib_path):
shutil.rmtree(lib_path) shutil.rmtree(lib_path)
if version_obj < LooseVersion("0.92"): if version_obj < AwesomeVersion("0.92"):
# 0.92 moved google/tts.py to google_translate/tts.py # 0.92 moved google/tts.py to google_translate/tts.py
config_path = hass.config.path(YAML_CONFIG_FILE) config_path = hass.config.path(YAML_CONFIG_FILE)
@ -388,7 +388,7 @@ def process_ha_config_upgrade(hass: HomeAssistant) -> None:
except OSError: except OSError:
_LOGGER.exception("Migrating to google_translate tts failed") _LOGGER.exception("Migrating to google_translate tts failed")
if version_obj < LooseVersion("0.94") and is_docker_env(): if version_obj < AwesomeVersion("0.94") and is_docker_env():
# In 0.94 we no longer install packages inside the deps folder when # In 0.94 we no longer install packages inside the deps folder when
# running inside a Docker container. # running inside a Docker container.
lib_path = hass.config.path("deps") lib_path = hass.config.path("deps")