-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle version checker errors appropriately, fixes https://githu…
- Loading branch information
1 parent
bd5fa42
commit 08774ea
Showing
2 changed files
with
24 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters