Skip to content

Commit

Permalink
Color output of check_latest packages
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Nov 17, 2023
1 parent 1bed137 commit 9cd6a7c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions scripts/check_latest_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

def main(*packages):
allowed_date = date.today() - timedelta(days=5)
is_latest = True
GREEN, RED, RESET = "\033[92m", "\033[91m", "\033[0m"
all_latest = True
for package in sorted(packages):
url = f"https://pypi.org/pypi/{package}/json"
resp = requests.get(url).json()
Expand All @@ -22,14 +23,16 @@ def main(*packages):
).date()

version_check = Version(current) >= Version(latest)
date_check = allowed_date >= latest_release_date
is_latest &= version_check or date_check
date_check = current_release_date >= allowed_date
is_latest = version_check or date_check
all_latest &= is_latest

text_color = GREEN if is_latest else RED
print(
f"Package: {package:<10} Current: {current:<7} ({current_release_date})\tLatest: {latest:<7} ({latest_release_date})"
f"{text_color}Package: {package:<10} Current: {current:<7} ({current_release_date})\tLatest: {latest:<7} ({latest_release_date}){RESET}"
)

if not is_latest:
if not all_latest:
sys.exit(1)


Expand Down

0 comments on commit 9cd6a7c

Please sign in to comment.