Skip to content

Commit

Permalink
fix/check-updates-fixes (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanpulver committed Sep 27, 2024
1 parent 15e757c commit dec98e0
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions safety/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import sys
from functools import wraps
from typing import Dict, Optional
from packaging import version as packaging_version
from packaging.version import InvalidVersion

import click
import typer
Expand Down Expand Up @@ -767,7 +769,7 @@ def check_updates(ctx: typer.Context,
details = [f"Organization: {organization}",
f"Account: {account}",
current_version,
f"Latest available version: {latest_available_version}"
f"Latest stable available version: {latest_available_version}"
]

for msg in details:
Expand All @@ -776,14 +778,25 @@ def check_updates(ctx: typer.Context,
console.print()

if latest_available_version:
console.print(f"Update available: Safety version {latest_available_version}")
console.print()
console.print(
f"If Safety was installed from a requirements file, update Safety to version {latest_available_version} in that requirements file."
)
console.print()
# `pip -i <source_url> install safety=={latest_available_version}` OR
console.print(f"Pip: To install the updated version of Safety directly via pip, run: `pip install safety=={latest_available_version}`")
try:
# Compare the current version and the latest available version using packaging.version
if packaging_version.parse(latest_available_version) > packaging_version.parse(VERSION):
console.print(f"Update available: Safety version {latest_available_version}")
console.print()
console.print(
f"If Safety was installed from a requirements file, update Safety to version {latest_available_version} in that requirements file."
)
console.print()
console.print(f"Pip: To install the updated version of Safety directly via pip, run: pip install safety=={latest_available_version}")
elif packaging_version.parse(latest_available_version) < packaging_version.parse(VERSION):
# Notify user about downgrading
console.print(f"Latest stable version is {latest_available_version}. If you want to downgrade to this version, you can run: pip install safety=={latest_available_version}")
else:
console.print("You are already using the latest stable version of Safety.")
except InvalidVersion as invalid_version:
LOG.exception(f'Invalid version format encountered: {invalid_version}')
console.print(f"Error: Invalid version format encountered for the latest available version: {latest_available_version}")
console.print("Please report this issue or try again later.")

if console.quiet:
console.quiet = False
Expand Down

0 comments on commit dec98e0

Please sign in to comment.