Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cirro/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import importlib

import click
import requests
from cirro_api_client.v1.errors import CirroException

from cirro.cli import run_ingest, run_download, run_configure, run_list_datasets, run_create_pipeline_config
Expand Down Expand Up @@ -125,8 +128,30 @@ def create_pipeline_config(**kwargs):
run_create_pipeline_config(kwargs, interactive=kwargs.get('interactive'))


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("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} "
f"is out of date. Update to {latest_version} with 'pip install cirro --upgrade'.")

except Exception:
return


def main():
try:
_check_version()
run()
except InputError as e:
handle_error(e)
Expand Down
29 changes: 0 additions & 29 deletions cirro/cli/controller.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import importlib.metadata
import json
import logging
import os
import sys
from pathlib import Path

import requests
from cirro_api_client.v1.models import UploadDatasetRequest, Status, Executor

from cirro.cirro_client import CirroApi
Expand Down Expand Up @@ -39,7 +37,6 @@
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()
Expand All @@ -66,7 +63,6 @@ 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)
Expand Down Expand Up @@ -125,7 +121,6 @@ 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}")

Expand Down Expand Up @@ -182,7 +177,6 @@ def run_download(input_params: DownloadArguments, interactive=False):

def run_upload_reference(input_params: UploadReferenceArguments, interactive=False):
_check_configure()
_check_version()
cirro = CirroApi()
logger.info(f"Collecting data from {cirro.configuration.base_url}")

Expand All @@ -207,7 +201,6 @@ def run_upload_reference(input_params: UploadReferenceArguments, interactive=Fal


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,
Expand All @@ -221,7 +214,6 @@ def run_create_pipeline_config(input_params: CreatePipelineConfigArguments, inte
Creates the pipeline configuration files for the CLI.
This is a placeholder function that can be expanded in the future.
"""
_check_version()
logger.info("Creating pipeline configuration files...")

if interactive:
Expand Down Expand Up @@ -277,27 +269,6 @@ 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("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} "
f"is out of date. Update to {latest_version} with 'pip install cirro --upgrade'.")

except Exception:
return


def handle_error(e: Exception):
logger.error(f"{e.__class__.__name__}: {e}")
sys.exit(1)
Loading