Skip to content

Commit

Permalink
fix: handle version checker errors appropriately, fixes https://githu…
Browse files Browse the repository at this point in the history
  • Loading branch information
THEGOLDENPRO committed Apr 4, 2024
1 parent bd5fa42 commit 08774ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 23 additions & 3 deletions mov_cli/utils/version.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
from __future__ import annotations

import httpx
from packaging import version
from devgoldyutils import LoggerAdapter, Colours

import mov_cli
from ..logger import mov_cli_logger

__all__ = ("update_available",)

logger = LoggerAdapter(mov_cli_logger, prefix = Colours.GREEN.apply("version"))

def update_available() -> bool:
pypi = httpx.get("https://pypi.org/pypi/mov-cli/json").json()
pypi_ver = pypi["info"]["version"]
logger.debug("Checking if mov-cli needs updating...")

update_fail_msg = "Failed to check for mov-cli update!"

try:
response = httpx.get("https://pypi.org/pypi/mov-cli/json")
except httpx.HTTPError as e:
logger.warning(update_fail_msg + f" Error: {e}")
return False

if response.status_code >= 400:
logger.warning(update_fail_msg + f" Response: {response}")
return False

pypi_json = response.json()
pypi_version: str = pypi_json["info"]["version"]

if pypi_ver > mov_cli.__version__:
if version.parse(pypi_version) > version.parse(mov_cli.__version__):
return True

return False
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
"Unidecode",
"thefuzz",
"deprecation",
"packaging",

# Included plugins
"mov-cli-test>=1.1.0"
Expand Down

0 comments on commit 08774ea

Please sign in to comment.