Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prompt before continuing when using an outdated version (DEV-3350) #850

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 26 additions & 9 deletions src/dsp_tools/cli/entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def run(args: list[str]) -> None:
InputError: if user input was wrong
InternalError: if the user cannot fix it
"""
_check_version()
default_dsp_api_url = "http://0.0.0.0:3333"
default_sipi_url = "http://0.0.0.0:1024"
root_user_email = "root@example.com"
Expand All @@ -56,6 +55,7 @@ def run(args: list[str]) -> None:
user_args=args,
parser=parser,
)
_check_version()
jnussbaum marked this conversation as resolved.
Show resolved Hide resolved
_log_cli_arguments(parsed_arguments)

try:
Expand All @@ -81,7 +81,13 @@ def run(args: list[str]) -> None:


def _check_version() -> None:
"""Check if the installed version of dsp-tools is up-to-date. If not, print a warning message."""
"""
Check if the installed version of dsp-tools is up-to-date.
If pypi.org cannot be reached, or if the latest version cannot be determined, do nothing.
If a new post-release version is available, print a message to the user, and return None.
If the base version (i.e. the major.minor.micro part of the version) is outdated,
ask the user if they want to exit or continue anyway.
"""
try:
response = requests.get("https://pypi.org/pypi/dsp-tools/json", timeout=15)
except requests.ConnectionError:
Expand All @@ -90,13 +96,24 @@ def _check_version() -> None:
return
latest = parse(response.json()["info"]["version"])
installed = parse(version("dsp-tools"))
if latest > installed:
msg = colored(
f"You are using DSP-TOOLS version {installed}, but version {latest} is available. "
"Consider upgrading via 'pip3 install --upgrade dsp-tools'.",
color="red",
)
print(msg)
if latest == installed:
return

msg = (
f"You are using DSP-TOOLS version {installed}, but version {latest} is available. "
"Consider upgrading via 'pip3 install --upgrade dsp-tools'.\n"
)
if latest.base_version == installed.base_version:
print(colored(msg, color="red"))
return

msg += "Continue anyway? [y/n]"
jnussbaum marked this conversation as resolved.
Show resolved Hide resolved
resp = None
while resp not in ["y", "n"]:
resp = input(colored(msg, color="red"))
if resp == "y":
return
sys.exit(1)


def _parse_arguments(
Expand Down