diff --git a/crunch/__version__.py b/crunch/__version__.py index c5d4557..636e78e 100644 --- a/crunch/__version__.py +++ b/crunch/__version__.py @@ -1,6 +1,6 @@ __title__ = 'crunch-cli' __description__ = 'crunch-cli - CLI of the CrunchDAO Platform' -__version__ = '1.2.0' +__version__ = '1.2.1' __author__ = 'Enzo CACERES' __author_email__ = 'enzo.caceres@crunchdao.com' __url__ = 'https://github.com/crunchdao/crunch-cli' diff --git a/crunch/api.py b/crunch/api.py index f02384e..326cb45 100644 --- a/crunch/api.py +++ b/crunch/api.py @@ -6,3 +6,7 @@ def __init__(self, message: str): class NeverSubmittedException(CrunchApiException): pass + + +class CurrentCrunchNotFoundException(CrunchApiException): + pass diff --git a/crunch/command/__init__.py b/crunch/command/__init__.py index 358800f..35b468b 100644 --- a/crunch/command/__init__.py +++ b/crunch/command/__init__.py @@ -1,5 +1,5 @@ from .convert import convert, convert_cells_to_file -from .download import download +from .download import download, download_no_data_available from .push import push, push_summary from .setup import setup from .test import test diff --git a/crunch/command/download.py b/crunch/command/download.py index 1f40155..65e230c 100644 --- a/crunch/command/download.py +++ b/crunch/command/download.py @@ -1,5 +1,6 @@ import os import typing +import datetime import click import requests @@ -129,3 +130,14 @@ def download( y_train_path, x_test_path ) + +def download_no_data_available(): + today = datetime.date.today() + + print("\n---") + + # competition lunch + if today <= datetime.date(2023, 5, 16): + print("The data will be released on May 16th, 2023, 05.00 PM CET") + else: + print("No data is available yet") diff --git a/crunch/command/setup.py b/crunch/command/setup.py index 1f91af4..16909af 100644 --- a/crunch/command/setup.py +++ b/crunch/command/setup.py @@ -14,7 +14,7 @@ def _check_if_already_exists(directory: str, force: bool): if os.path.exists(directory): if force: - print(f"{directory}: deleting") + print(f"delete {directory}") shutil.rmtree(directory) else: print(f"{directory}: already exists (use --force to override)") diff --git a/crunch/inline.py b/crunch/inline.py index 54fef9b..93975f1 100644 --- a/crunch/inline.py +++ b/crunch/inline.py @@ -6,7 +6,7 @@ import click import pandas -from . import command, constants, tester, utils +from . import command, constants, tester, utils, api class _Inline: @@ -24,13 +24,17 @@ def __init__(self, module: typing.Any, model_directory: str): print(f"loaded inline runner with module: {module}") def load_data(self) -> typing.Tuple[pandas.DataFrame, pandas.DataFrame, pandas.DataFrame]: - ( - _, - _, - x_train_path, - y_train_path, - x_test_path - ) = command.download(self.session) + try: + ( + _, + _, + x_train_path, + y_train_path, + x_test_path + ) = command.download(self.session) + except api.CurrentCrunchNotFoundException: + command.download_no_data_available() + raise click.Abort() x_train = utils.read(x_train_path) y_train = utils.read(y_train_path) diff --git a/crunch/main.py b/crunch/main.py index 09a6c8a..12001fb 100644 --- a/crunch/main.py +++ b/crunch/main.py @@ -2,7 +2,7 @@ import click -from . import command, constants, utils +from . import command, constants, utils, api session = None debug = False @@ -65,7 +65,11 @@ def setup( if not no_data: os.chdir(directory) - command.download(session, force=True) + + try: + command.download(session, force=True) + except api.CurrentCrunchNotFoundException: + command.download_no_data_available() print("\n---") print(f"Success! Your environment has been correctly setup.") @@ -142,7 +146,10 @@ def test( def download(): utils.change_root() - command.download(session) + try: + command.download(session) + except api.CurrentCrunchNotFoundException: + command.download_no_data_available() @cli.command(help="Convert a notebook to a python script.") diff --git a/crunch/tester.py b/crunch/tester.py index ef1635c..2ef6a9b 100644 --- a/crunch/tester.py +++ b/crunch/tester.py @@ -7,8 +7,9 @@ import pandas import psutil import requests +import click -from . import command, constants, ensure, utils +from . import command, constants, ensure, utils, api def _get_process_memory() -> int: @@ -49,13 +50,17 @@ def run( train_handler = ensure.is_function(module, "train") infer_handler = ensure.is_function(module, "infer") - ( - embargo, - moon_column_name, - x_train_path, - y_train_path, - x_test_path - ) = command.download(session) + try: + ( + embargo, + moon_column_name, + x_train_path, + y_train_path, + x_test_path + ) = command.download(session) + except api.CurrentCrunchNotFoundException: + command.download_no_data_available() + raise click.Abort() x_train = utils.read(x_train_path) y_train = utils.read(y_train_path) diff --git a/crunch/utils.py b/crunch/utils.py index 3725c1a..5682fb3 100644 --- a/crunch/utils.py +++ b/crunch/utils.py @@ -49,6 +49,8 @@ def request(self, method, url, *args, **kwargs): self.print_recopy_command() elif code == "NEVER_SUBMITTED": raise api.NeverSubmittedException(message) + elif code == "CURRENT_CRUNCH_NOT_FOUND": + raise api.CurrentCrunchNotFoundException(message) else: print(f"{method} {url}: {status_code}") print(json.dumps(error, indent=4))