1"""Utility functions for version checking."""
3import importlib.metadata
8_logger = logging.getLogger(__name__)
11def check_for_update(package_name="aas-http-client"):
12 """Check for updates of the package on PyPI.
14 :param package_name: The name of the package to check for updates, defaults to "aas-http-client"
17 current_version = importlib.metadata.version(package_name)
18 pypi_url = f
"https://pypi.org/pypi/{package_name}/json"
19 latest_version = requests.get(pypi_url, timeout=3).json()[
"info"][
"version"]
21 if current_version != latest_version:
23 f
"⚠️ A new version for package '{package_name}' is available: "
24 f
"{latest_version} (currently installed: {current_version}). "
25 f
"Use the following command to update the package: pip install --upgrade {package_name}"
27 except Exception
as exc:
28 _logger.exception(f
"Exception occurred while checking for package update: {exc}")