Skip to content

Commit 5e42fff

Browse files
authored
Cleanup: Move check_version to main cli entrypoint (#171)
1 parent 66cf501 commit 5e42fff

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

cirro/cli/cli.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import importlib
2+
13
import click
4+
import requests
25
from cirro_api_client.v1.errors import CirroException
36

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

127130

131+
def _check_version():
132+
"""
133+
Prompts the user to update their package version if needed
134+
"""
135+
yellow_color = '\033[93m'
136+
reset_color = '\033[0m'
137+
138+
try:
139+
current_version = importlib.metadata.version('cirro')
140+
response = requests.get("https://pypi.org/pypi/cirro/json")
141+
response.raise_for_status()
142+
latest_version = response.json()["info"]["version"]
143+
144+
if current_version != latest_version:
145+
print(f"{yellow_color}Warning:{reset_color} Cirro version {current_version} "
146+
f"is out of date. Update to {latest_version} with 'pip install cirro --upgrade'.")
147+
148+
except Exception:
149+
return
150+
151+
128152
def main():
129153
try:
154+
_check_version()
130155
run()
131156
except InputError as e:
132157
handle_error(e)

cirro/cli/controller.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import importlib.metadata
21
import json
32
import logging
43
import os
54
import sys
65
from pathlib import Path
76

8-
import requests
97
from cirro_api_client.v1.models import UploadDatasetRequest, Status, Executor
108

119
from cirro.cirro_client import CirroApi
@@ -39,7 +37,6 @@
3937
def run_list_datasets(input_params: ListArguments, interactive=False):
4038
"""List the datasets available in a particular project."""
4139
_check_configure()
42-
_check_version()
4340
cirro = CirroApi()
4441
logger.info(f"Collecting data from {cirro.configuration.base_url}")
4542
projects = cirro.projects.list()
@@ -66,7 +63,6 @@ def run_list_datasets(input_params: ListArguments, interactive=False):
6663

6764
def run_ingest(input_params: UploadArguments, interactive=False):
6865
_check_configure()
69-
_check_version()
7066
cirro = CirroApi()
7167
logger.info(f"Collecting data from {cirro.configuration.base_url}")
7268
processes = cirro.processes.list(process_type=Executor.INGEST)
@@ -125,7 +121,6 @@ def run_ingest(input_params: UploadArguments, interactive=False):
125121

126122
def run_download(input_params: DownloadArguments, interactive=False):
127123
_check_configure()
128-
_check_version()
129124
cirro = CirroApi()
130125
logger.info(f"Collecting data from {cirro.configuration.base_url}")
131126

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

183178
def run_upload_reference(input_params: UploadReferenceArguments, interactive=False):
184179
_check_configure()
185-
_check_version()
186180
cirro = CirroApi()
187181
logger.info(f"Collecting data from {cirro.configuration.base_url}")
188182

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

208202

209203
def run_configure():
210-
_check_version()
211204
auth_method, base_url, auth_method_config, enable_additional_checksum = gather_auth_config()
212205
save_user_config(UserConfig(auth_method=auth_method,
213206
auth_method_config=auth_method_config,
@@ -221,7 +214,6 @@ def run_create_pipeline_config(input_params: CreatePipelineConfigArguments, inte
221214
Creates the pipeline configuration files for the CLI.
222215
This is a placeholder function that can be expanded in the future.
223216
"""
224-
_check_version()
225217
logger.info("Creating pipeline configuration files...")
226218

227219
if interactive:
@@ -277,27 +269,6 @@ def _check_configure():
277269
run_configure()
278270

279271

280-
def _check_version():
281-
"""
282-
Prompts the user to update their package version if needed
283-
"""
284-
yellow_color = '\033[93m'
285-
reset_color = '\033[0m'
286-
287-
try:
288-
current_version = importlib.metadata.version('cirro')
289-
response = requests.get("https://pypi.org/pypi/cirro/json")
290-
response.raise_for_status()
291-
latest_version = response.json()["info"]["version"]
292-
293-
if current_version != latest_version:
294-
print(f"{yellow_color}Warning:{reset_color} Cirro version {current_version} "
295-
f"is out of date. Update to {latest_version} with 'pip install cirro --upgrade'.")
296-
297-
except Exception:
298-
return
299-
300-
301272
def handle_error(e: Exception):
302273
logger.error(f"{e.__class__.__name__}: {e}")
303274
sys.exit(1)

0 commit comments

Comments
 (0)