From 0e27fcb5ffa146bc28efd7b85bc813ba47f1640b Mon Sep 17 00:00:00 2001 From: Shannon Osborne <31218961+shanosborne@users.noreply.github.com> Date: Wed, 14 May 2025 14:18:47 -0700 Subject: [PATCH 1/3] add version warning --- cirro/cli/controller.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cirro/cli/controller.py b/cirro/cli/controller.py index 048d3624..a54f87fe 100644 --- a/cirro/cli/controller.py +++ b/cirro/cli/controller.py @@ -1,5 +1,7 @@ import logging +import importlib.metadata import os +import requests import sys import pandas as pd @@ -32,6 +34,7 @@ def run_list_datasets(input_params: ListArguments, interactive=False): """List the datasets available in a particular project.""" _check_configure() + _check_version() cirro = CirroApi() logger.info(f"Collecting data from {cirro.configuration.base_url}") projects = cirro.projects.list() @@ -56,6 +59,7 @@ def run_list_datasets(input_params: ListArguments, interactive=False): def run_ingest(input_params: UploadArguments, interactive=False): _check_configure() + _check_version() cirro = CirroApi() logger.info(f"Collecting data from {cirro.configuration.base_url}") processes = cirro.processes.list(process_type=Executor.INGEST) @@ -112,6 +116,7 @@ def run_ingest(input_params: UploadArguments, interactive=False): def run_download(input_params: DownloadArguments, interactive=False): _check_configure() + _check_version() cirro = CirroApi() logger.info(f"Collecting data from {cirro.configuration.base_url}") @@ -171,6 +176,7 @@ def run_download(input_params: DownloadArguments, interactive=False): def run_configure(): + _check_version() auth_method, base_url, auth_method_config, enable_additional_checksum = gather_auth_config() save_user_config(UserConfig(auth_method=auth_method, auth_method_config=auth_method_config, @@ -193,6 +199,26 @@ def _check_configure(): run_configure() +def _check_version(): + """ + Prompts the user to update their package version if needed + """ + yellow_color = '\033[93m' + reset_color = '\033[0m' + + try: + current_version = importlib.metadata.version('cirro') + response = requests.get(f"https://pypi.org/pypi/cirro/json") + response.raise_for_status() + latest_version = response.json()["info"]["version"] + + if current_version != latest_version: + print(f"{yellow_color} Warning:{reset_color} Cirro version {current_version} is out of date. Update to {latest_version} with 'pip install cirro --upgrade'.") + + except Exception as e: + return + + def handle_error(e: Exception): logger.error(f"{e.__class__.__name__}: {e}") sys.exit(1) From 083b3b64bf052ea5094c88e0c2c17d5390b51093 Mon Sep 17 00:00:00 2001 From: Shannon Osborne <31218961+shanosborne@users.noreply.github.com> Date: Wed, 14 May 2025 14:22:02 -0700 Subject: [PATCH 2/3] remove space --- cirro/cli/controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cirro/cli/controller.py b/cirro/cli/controller.py index a54f87fe..7ef832dc 100644 --- a/cirro/cli/controller.py +++ b/cirro/cli/controller.py @@ -213,7 +213,7 @@ def _check_version(): latest_version = response.json()["info"]["version"] if current_version != latest_version: - print(f"{yellow_color} Warning:{reset_color} Cirro version {current_version} is out of date. Update to {latest_version} with 'pip install cirro --upgrade'.") + print(f"{yellow_color}Warning:{reset_color} Cirro version {current_version} is out of date. Update to {latest_version} with 'pip install cirro --upgrade'.") except Exception as e: return From 2f3dfe642209840595ed27c5de8285f6bf5607c7 Mon Sep 17 00:00:00 2001 From: Shannon Osborne <31218961+shanosborne@users.noreply.github.com> Date: Wed, 14 May 2025 14:32:43 -0700 Subject: [PATCH 3/3] linter --- cirro/cli/controller.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cirro/cli/controller.py b/cirro/cli/controller.py index 7ef832dc..c426fe60 100644 --- a/cirro/cli/controller.py +++ b/cirro/cli/controller.py @@ -208,14 +208,15 @@ def _check_version(): try: current_version = importlib.metadata.version('cirro') - response = requests.get(f"https://pypi.org/pypi/cirro/json") + response = requests.get("https://pypi.org/pypi/cirro/json") response.raise_for_status() latest_version = response.json()["info"]["version"] if current_version != latest_version: - print(f"{yellow_color}Warning:{reset_color} Cirro version {current_version} is out of date. Update to {latest_version} with 'pip install cirro --upgrade'.") + print(f"{yellow_color}Warning:{reset_color} Cirro version {current_version} " + f"is out of date. Update to {latest_version} with 'pip install cirro --upgrade'.") - except Exception as e: + except Exception: return