From 14413554de5ce52b07f0e8bd0f995b5024f73050 Mon Sep 17 00:00:00 2001 From: manskx Date: Thu, 6 Oct 2022 15:03:29 +0200 Subject: [PATCH 01/18] Allow force run app on cloud if loading locally errors --- src/lightning_app/runners/cloud.py | 40 +++++++++++++++++++++++++ src/lightning_app/runners/runtime.py | 5 ++++ src/lightning_app/utilities/load_app.py | 40 +++++++++++++++++-------- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index a9fabad6d25d8..0b1d195135521 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -4,10 +4,13 @@ import string import sys import time +import traceback from dataclasses import dataclass from pathlib import Path from typing import Any, Callable, List, Optional, Union +import click +from lightning_app.utilities.load_app import load_app_from_file, _prettifiy_exception from lightning_cloud.openapi import ( Body3, Body4, @@ -398,3 +401,40 @@ def _project_has_sufficient_credits(self, project: V1Membership, app: Optional[L balance = 0 # value is missing in some tests return balance >= 1 + + @classmethod + def _should_force_run_app_on_cloud_promote(cls, filepath: str) -> bool: + # we want to format the exception as if no frame was on top. + exp, val, tb = sys.exc_info() + listing = traceback.format_exception(exp, val, tb) + # remove the entry for the first frame + del listing[1] + listing = [ + f"Found an exception when loading your application from {filepath}.\n\n" + ] + listing + logger.error("".join(listing)) + click.echo("Maybe some dependencies are missing? If you want to force run the on cloud, please type 'y'.") + value = input("\nPress enter to continue: ") + value = value.strip().lower() + is_force_run = len(value) == 0 or value in {"y", "yes", 1} + return is_force_run + + @classmethod + def load_app_from_file(cls, filepath: str) -> "LightningApp": + """This is meant to use only locally for cloud runtime.""" + try: + app = load_app_from_file(filepath, raise_exception=True) + except ModuleNotFoundError as e: + # this is very generic exception. + is_force_run = cls._show_loading_app_module_error(filepath) + if is_force_run: + from lightning.app.testing.helpers import EmptyFlow + # Create a mocking app. + app = LightningApp(EmptyFlow()) + else: + sys.exit(1) + except FileNotFoundError as e: + raise e + except Exception: + _prettifiy_exception(filepath) + return app diff --git a/src/lightning_app/runners/runtime.py b/src/lightning_app/runners/runtime.py index 64d5c1050214b..d69960b6d3872 100644 --- a/src/lightning_app/runners/runtime.py +++ b/src/lightning_app/runners/runtime.py @@ -149,3 +149,8 @@ def _add_stopped_status_to_work(self, work: "lightning_app.LightningWork") -> No latest_call_hash = work._calls[CacheCallsKeys.LATEST_CALL_HASH] if latest_call_hash in work._calls: work._calls[latest_call_hash]["statuses"].append(make_status(WorkStageStatus.STOPPED)) + + @classmethod + def load_app_from_file(cls, filepath: str) -> "LightningApp": + + return load_app_from_file(filepath) diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index 614944bc7e249..68a3f105632d7 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -15,8 +15,31 @@ logger = Logger(__name__) +def _prettifiy_exception(filepath: str): + """ + Pretty print the exception that occurred when loading the app. + :param filepath: + :return: + """ + # we want to format the exception as if no frame was on top. + exp, val, tb = sys.exc_info() + listing = traceback.format_exception(exp, val, tb) + # remove the entry for the first frame + del listing[1] + listing = [ + f"Found an exception when loading your application from {filepath}. Please, resolve it to run your app.\n\n" + ] + listing + logger.error("".join(listing)) + sys.exit(1) + + +def load_app_from_file(filepath: str, raise_exception: bool = False) -> "LightningApp": + """ + Load a LightningApp from a file. + :param filepath: The path to the file containing the LightningApp. + :param raise_exception: If True, raise an exception if the app cannot be loaded. + """ -def load_app_from_file(filepath: str) -> "LightningApp": # Taken from StreamLit: https://github.com/streamlit/streamlit/blob/develop/lib/streamlit/script_runner.py#L313 from lightning_app.core.app import LightningApp @@ -30,17 +53,10 @@ def load_app_from_file(filepath: str) -> "LightningApp": try: with _patch_sys_argv(): exec(code, module.__dict__) - except Exception: - # we want to format the exception as if no frame was on top. - exp, val, tb = sys.exc_info() - listing = traceback.format_exception(exp, val, tb) - # remove the entry for the first frame - del listing[1] - listing = [ - f"Found an exception when loading your application from {filepath}. Please, resolve it to run your app.\n\n" - ] + listing - logger.error("".join(listing)) - sys.exit(1) + except Exception as e: + if raise_exception: + raise e + _pretty_exception(filepath) apps = [v for v in module.__dict__.values() if isinstance(v, LightningApp)] if len(apps) > 1: From c4a98c8f45cdfd66381af62ed642d56c3acf294f Mon Sep 17 00:00:00 2001 From: manskx Date: Thu, 6 Oct 2022 15:04:35 +0200 Subject: [PATCH 02/18] typo --- src/lightning_app/utilities/load_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index 68a3f105632d7..094cfd5a491bf 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -56,7 +56,7 @@ def load_app_from_file(filepath: str, raise_exception: bool = False) -> "Lightni except Exception as e: if raise_exception: raise e - _pretty_exception(filepath) + _prettifiy_exception(filepath) apps = [v for v in module.__dict__.values() if isinstance(v, LightningApp)] if len(apps) > 1: From 763d358f53ccdc773ee344c45e1e5fac6130efb9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Oct 2022 13:06:12 +0000 Subject: [PATCH 03/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/lightning_app/runners/cloud.py | 7 +++---- src/lightning_app/utilities/load_app.py | 13 +++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 0b1d195135521..4948b19095ac6 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -10,7 +10,6 @@ from typing import Any, Callable, List, Optional, Union import click -from lightning_app.utilities.load_app import load_app_from_file, _prettifiy_exception from lightning_cloud.openapi import ( Body3, Body4, @@ -59,6 +58,7 @@ from lightning_app.utilities.app_helpers import Logger from lightning_app.utilities.cloud import _get_project from lightning_app.utilities.dependency_caching import get_hash +from lightning_app.utilities.load_app import _prettifiy_exception, load_app_from_file from lightning_app.utilities.packaging.app_config import AppConfig, find_config_file from lightning_app.utilities.packaging.lightning_utils import _prepare_lightning_wheels_and_requirements from lightning_app.utilities.secrets import _names_to_ids @@ -409,9 +409,7 @@ def _should_force_run_app_on_cloud_promote(cls, filepath: str) -> bool: listing = traceback.format_exception(exp, val, tb) # remove the entry for the first frame del listing[1] - listing = [ - f"Found an exception when loading your application from {filepath}.\n\n" - ] + listing + listing = [f"Found an exception when loading your application from {filepath}.\n\n"] + listing logger.error("".join(listing)) click.echo("Maybe some dependencies are missing? If you want to force run the on cloud, please type 'y'.") value = input("\nPress enter to continue: ") @@ -429,6 +427,7 @@ def load_app_from_file(cls, filepath: str) -> "LightningApp": is_force_run = cls._show_loading_app_module_error(filepath) if is_force_run: from lightning.app.testing.helpers import EmptyFlow + # Create a mocking app. app = LightningApp(EmptyFlow()) else: diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index 094cfd5a491bf..6214f8907af8c 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -15,9 +15,10 @@ logger = Logger(__name__) + def _prettifiy_exception(filepath: str): - """ - Pretty print the exception that occurred when loading the app. + """Pretty print the exception that occurred when loading the app. + :param filepath: :return: """ @@ -27,15 +28,15 @@ def _prettifiy_exception(filepath: str): # remove the entry for the first frame del listing[1] listing = [ - f"Found an exception when loading your application from {filepath}. Please, resolve it to run your app.\n\n" - ] + listing + f"Found an exception when loading your application from {filepath}. Please, resolve it to run your app.\n\n" + ] + listing logger.error("".join(listing)) sys.exit(1) def load_app_from_file(filepath: str, raise_exception: bool = False) -> "LightningApp": - """ - Load a LightningApp from a file. + """Load a LightningApp from a file. + :param filepath: The path to the file containing the LightningApp. :param raise_exception: If True, raise an exception if the app cannot be loaded. """ From 6e72a37d0ffee9cbacdd9d2ffab1dc1600bbed39 Mon Sep 17 00:00:00 2001 From: manskx Date: Fri, 7 Oct 2022 11:38:51 +0200 Subject: [PATCH 04/18] update the message --- src/lightning_app/runners/cloud.py | 10 +++++----- src/lightning_app/runners/runtime.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 0b1d195135521..d282c6724477e 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -409,14 +409,14 @@ def _should_force_run_app_on_cloud_promote(cls, filepath: str) -> bool: listing = traceback.format_exception(exp, val, tb) # remove the entry for the first frame del listing[1] - listing = [ - f"Found an exception when loading your application from {filepath}.\n\n" - ] + listing - logger.error("".join(listing)) + + click.echo(f"Found an exception when loading your application from {filepath}.\n") click.echo("Maybe some dependencies are missing? If you want to force run the on cloud, please type 'y'.") value = input("\nPress enter to continue: ") value = value.strip().lower() is_force_run = len(value) == 0 or value in {"y", "yes", 1} + if not is_force_run: + logger.error("".join(listing)) return is_force_run @classmethod @@ -426,7 +426,7 @@ def load_app_from_file(cls, filepath: str) -> "LightningApp": app = load_app_from_file(filepath, raise_exception=True) except ModuleNotFoundError as e: # this is very generic exception. - is_force_run = cls._show_loading_app_module_error(filepath) + is_force_run = cls._should_force_run_app_on_cloud_promote(filepath) if is_force_run: from lightning.app.testing.helpers import EmptyFlow # Create a mocking app. diff --git a/src/lightning_app/runners/runtime.py b/src/lightning_app/runners/runtime.py index d69960b6d3872..cc11fa3b3aeff 100644 --- a/src/lightning_app/runners/runtime.py +++ b/src/lightning_app/runners/runtime.py @@ -54,7 +54,7 @@ def dispatch( runtime_type = RuntimeType(runtime_type) runtime_cls: Type[Runtime] = runtime_type.get_runtime() - app = load_app_from_file(str(entrypoint_file)) + app = runtime_cls.load_app_from_file(str(entrypoint_file)) env_vars = {} if env_vars is None else env_vars secrets = {} if secrets is None else secrets From 7d1c48b2553f6088f7c178c5a53c9ba85b811574 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 7 Oct 2022 09:46:41 +0000 Subject: [PATCH 05/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/lightning_app/runners/cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 9ebdecc69a2e9..105ee46968f89 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -10,7 +10,6 @@ from typing import Any, Callable, List, Optional, Union import click -from lightning_app.utilities.load_app import load_app_from_file, _prettifiy_exception from lightning_cloud.openapi import ( Body3, Body4, @@ -59,6 +58,7 @@ from lightning_app.utilities.app_helpers import Logger from lightning_app.utilities.cloud import _get_project from lightning_app.utilities.dependency_caching import get_hash +from lightning_app.utilities.load_app import _prettifiy_exception, load_app_from_file from lightning_app.utilities.packaging.app_config import AppConfig, find_config_file from lightning_app.utilities.packaging.lightning_utils import _prepare_lightning_wheels_and_requirements from lightning_app.utilities.secrets import _names_to_ids From f648685ae1fcd0655796d5eddef7ab193b5962c7 Mon Sep 17 00:00:00 2001 From: manskx Date: Fri, 7 Oct 2022 17:43:07 +0200 Subject: [PATCH 06/18] add tests --- src/lightning_app/runners/cloud.py | 4 +--- tests/tests_app/runners/test_cloud.py | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 105ee46968f89..6f32a9831496c 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -428,14 +428,12 @@ def load_app_from_file(cls, filepath: str) -> "LightningApp": # this is very generic exception. is_force_run = cls._should_force_run_app_on_cloud_promote(filepath) if is_force_run: - from lightning.app.testing.helpers import EmptyFlow + from lightning_app.testing.helpers import EmptyFlow # Create a mocking app. app = LightningApp(EmptyFlow()) else: sys.exit(1) - except FileNotFoundError as e: - raise e except Exception: _prettifiy_exception(filepath) return app diff --git a/tests/tests_app/runners/test_cloud.py b/tests/tests_app/runners/test_cloud.py index fcf53d92b7f00..85f51788522a4 100644 --- a/tests/tests_app/runners/test_cloud.py +++ b/tests/tests_app/runners/test_cloud.py @@ -30,13 +30,17 @@ V1Work, ) -from lightning_app import LightningApp, LightningWork -from lightning_app.runners import backends, cloud +from lightning_app import LightningApp, LightningWork, _PROJECT_ROOT +from lightning_app.runners import backends, cloud, CloudRuntime from lightning_app.storage import Drive +from lightning_app.testing.helpers import EmptyFlow from lightning_app.utilities.cloud import _get_project from lightning_app.utilities.dependency_caching import get_hash +import os + + class MyWork(LightningWork): def run(self): print("my run") @@ -702,3 +706,20 @@ def test_project_has_sufficient_credits(): for balance, result in credits_and_test_value: project = V1Membership(name="test-project1", project_id="test-project-id1", balance=balance) assert cloud_runtime._project_has_sufficient_credits(project) is result + + +@mock.patch( + "lightning_app.runners.cloud.load_app_from_file", + MagicMock(side_effect=ModuleNotFoundError("Module X not found")), +) +def test_load_app_from_file_module_error(): + import builtins + + with mock.patch.object(builtins, "input", lambda _: "y"): + empty_app = CloudRuntime.load_app_from_file(os.path.join(_PROJECT_ROOT, "examples", "app_v0", "app.py")) + isinstance(empty_app, LightningApp) + isinstance(empty_app.root, EmptyFlow) + + with mock.patch.object(builtins, "input", lambda _: "n"), pytest.raises(SystemExit): + return_empty = CloudRuntime.load_app_from_file(os.path.join(_PROJECT_ROOT, "examples", "app_v0", "app.py")) + assert return_empty is None From bc8c1dd49c06005f99c7d89403a2711456a72541 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 7 Oct 2022 15:45:07 +0000 Subject: [PATCH 07/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/tests_app/runners/test_cloud.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/tests_app/runners/test_cloud.py b/tests/tests_app/runners/test_cloud.py index 85f51788522a4..4a17d9d0c00d5 100644 --- a/tests/tests_app/runners/test_cloud.py +++ b/tests/tests_app/runners/test_cloud.py @@ -1,4 +1,5 @@ import logging +import os from copy import copy from pathlib import Path from unittest import mock @@ -30,7 +31,7 @@ V1Work, ) -from lightning_app import LightningApp, LightningWork, _PROJECT_ROOT +from lightning_app import _PROJECT_ROOT, LightningApp, LightningWork from lightning_app.runners import backends, cloud, CloudRuntime from lightning_app.storage import Drive from lightning_app.testing.helpers import EmptyFlow @@ -38,9 +39,6 @@ from lightning_app.utilities.dependency_caching import get_hash -import os - - class MyWork(LightningWork): def run(self): print("my run") From 079ecb7b2eb14e9e7098fc5c282c1f9e4979c1d3 Mon Sep 17 00:00:00 2001 From: manskx Date: Wed, 26 Oct 2022 19:50:38 +0200 Subject: [PATCH 08/18] update test --- tests/tests_app/runners/test_cloud.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/tests_app/runners/test_cloud.py b/tests/tests_app/runners/test_cloud.py index 02075b2ba337f..22b48472fcc66 100644 --- a/tests/tests_app/runners/test_cloud.py +++ b/tests/tests_app/runners/test_cloud.py @@ -34,8 +34,8 @@ V1Work, ) -from lightning_app import LightningApp, LightningWork -from lightning_app.runners import backends, cloud +from lightning_app import LightningApp, LightningWork, _PROJECT_ROOT +from lightning_app.runners import backends, cloud, CloudRuntime from lightning_app.storage import Drive, Mount from lightning_app.utilities.cloud import _get_project from lightning_app.utilities.dependency_caching import get_hash @@ -1010,13 +1010,6 @@ def test_project_has_sufficient_credits(): MagicMock(side_effect=ModuleNotFoundError("Module X not found")), ) def test_load_app_from_file_module_error(): - import builtins - - with mock.patch.object(builtins, "input", lambda _: "y"): - empty_app = CloudRuntime.load_app_from_file(os.path.join(_PROJECT_ROOT, "examples", "app_v0", "app.py")) - isinstance(empty_app, LightningApp) - isinstance(empty_app.root, EmptyFlow) - - with mock.patch.object(builtins, "input", lambda _: "n"), pytest.raises(SystemExit): - return_empty = CloudRuntime.load_app_from_file(os.path.join(_PROJECT_ROOT, "examples", "app_v0", "app.py")) - assert return_empty is None + empty_app = CloudRuntime.load_app_from_file(os.path.join(_PROJECT_ROOT, "examples", "app_v0", "app.py")) + assert isinstance(empty_app, LightningApp) + assert isinstance(empty_app.root, EmptyFlow) From d09b61c1768fa7b1dcc9aa08b8aa969d7b523091 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:54:56 +0000 Subject: [PATCH 09/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/lightning_app/runners/cloud.py | 3 ++- tests/tests_app/runners/test_cloud.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 855d38f8b0d2c..9930e5d41f83e 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -471,6 +471,7 @@ def load_app_from_file(cls, filepath: str) -> "LightningApp": _prettifiy_exception(filepath) return app + def _create_mount_drive_spec(work_name: str, mount: Mount) -> V1LightningworkDrives: if mount.protocol == "s3://": drive_type = V1DriveType.INDEXED_S3 @@ -494,4 +495,4 @@ def _create_mount_drive_spec(work_name: str, mount: Mount) -> V1LightningworkDri status=V1DriveStatus(), ), mount_location=str(mount.mount_path), - ) \ No newline at end of file + ) diff --git a/tests/tests_app/runners/test_cloud.py b/tests/tests_app/runners/test_cloud.py index 22b48472fcc66..b10c3c4e8337a 100644 --- a/tests/tests_app/runners/test_cloud.py +++ b/tests/tests_app/runners/test_cloud.py @@ -34,13 +34,13 @@ V1Work, ) -from lightning_app import LightningApp, LightningWork, _PROJECT_ROOT +from lightning_app import _PROJECT_ROOT, LightningApp, LightningWork from lightning_app.runners import backends, cloud, CloudRuntime from lightning_app.storage import Drive, Mount +from lightning_app.testing.helpers import EmptyFlow from lightning_app.utilities.cloud import _get_project from lightning_app.utilities.dependency_caching import get_hash from lightning_app.utilities.packaging.cloud_compute import CloudCompute -from lightning_app.testing.helpers import EmptyFlow class MyWork(LightningWork): From 5805a153ecb8da6dc10fa20d38c567da2049779c Mon Sep 17 00:00:00 2001 From: manskx Date: Wed, 26 Oct 2022 19:57:44 +0200 Subject: [PATCH 10/18] remove confirmation --- src/lightning_app/runners/cloud.py | 33 ++++++++---------------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 855d38f8b0d2c..1d18485354bae 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -435,23 +435,6 @@ def _project_has_sufficient_credits(self, project: V1Membership, app: Optional[L return balance >= 1 - @classmethod - def _should_force_run_app_on_cloud_promote(cls, filepath: str) -> bool: - # we want to format the exception as if no frame was on top. - exp, val, tb = sys.exc_info() - listing = traceback.format_exception(exp, val, tb) - # remove the entry for the first frame - del listing[1] - - click.echo(f"Found an exception when loading your application from {filepath}.\n") - click.echo("Maybe some dependencies are missing? If you want to force run the on cloud, please type 'y'.") - value = input("\nPress enter to continue: ") - value = value.strip().lower() - is_force_run = len(value) == 0 or value in {"y", "yes", 1} - if not is_force_run: - logger.error("".join(listing)) - return is_force_run - @classmethod def load_app_from_file(cls, filepath: str) -> "LightningApp": """This is meant to use only locally for cloud runtime.""" @@ -459,14 +442,16 @@ def load_app_from_file(cls, filepath: str) -> "LightningApp": app = load_app_from_file(filepath, raise_exception=True) except ModuleNotFoundError as e: # this is very generic exception. - is_force_run = cls._should_force_run_app_on_cloud_promote(filepath) - if is_force_run: - from lightning_app.testing.helpers import EmptyFlow + logger.info("Could not load the app() locally. Starting the app directly on the cloud.") + # we want to format the exception as if no frame was on top. + exp, val, tb = sys.exc_info() + listing = traceback.format_exception(exp, val, tb) + # remove the entry for the first frame + del listing[1] + from lightning_app.testing.helpers import EmptyFlow + # Create a mocking app. + app = LightningApp(EmptyFlow()) - # Create a mocking app. - app = LightningApp(EmptyFlow()) - else: - sys.exit(1) except Exception: _prettifiy_exception(filepath) return app From 2af4a5734a05d897db4a39b70e1f18d7c4d637b4 Mon Sep 17 00:00:00 2001 From: manskx Date: Wed, 26 Oct 2022 20:03:58 +0200 Subject: [PATCH 11/18] unused import --- src/lightning_app/runners/cloud.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index c7ffebc3c8acb..7f1d9eeef86da 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -9,7 +9,6 @@ from pathlib import Path from typing import Any, Callable, List, Optional, Union -import click from lightning_cloud.openapi import ( Body3, Body4, From 2bcb9988de80e999144d727e2e306efdf5160f95 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Oct 2022 18:09:27 +0000 Subject: [PATCH 12/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/lightning_app/runners/cloud.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 7f1d9eeef86da..9e5a26e88e403 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -448,6 +448,7 @@ def load_app_from_file(cls, filepath: str) -> "LightningApp": # remove the entry for the first frame del listing[1] from lightning_app.testing.helpers import EmptyFlow + # Create a mocking app. app = LightningApp(EmptyFlow()) From f3b8383c34f60f3fdca25cd405510161bb4f4e2e Mon Sep 17 00:00:00 2001 From: manskx Date: Thu, 27 Oct 2022 12:44:22 +0200 Subject: [PATCH 13/18] Add changelog --- src/lightning_app/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index 10ab8626abc8b..13033dbf391d9 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added support getting CLI help for connected apps even if the app isn't running ([#15196](https://github.com/Lightning-AI/lightning/pull/15196) - Added support for adding requirements to commands and installing them when missing when running an app command ([#15198](https://github.com/Lightning-AI/lightning/pull/15198) - Added Lightning CLI Connection to be terminal session instead of global ([#15241](https://github.com/Lightning-AI/lightning/pull/15241) +- Added support to start lightning app on cloud without needing to install dependencies locally ([#15019](https://github.com/Lightning-AI/lightning/pull/15019) ### Changed From 06d6205defbf294fabf4fa52c1b69901e16251e7 Mon Sep 17 00:00:00 2001 From: manskx Date: Mon, 31 Oct 2022 12:38:44 +0100 Subject: [PATCH 14/18] fix notfound errors --- src/lightning_app/runners/cloud.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 26b4b7ad50d49..6adcb0eb48000 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -483,6 +483,8 @@ def load_app_from_file(cls, filepath: str) -> "LightningApp": # Create a mocking app. app = LightningApp(EmptyFlow()) + except FileNotFoundError as e: + raise e except Exception: _prettifiy_exception(filepath) return app From b3d1319756be70b9362b5356d22a91aa11d43b55 Mon Sep 17 00:00:00 2001 From: manskx Date: Mon, 31 Oct 2022 17:27:14 +0100 Subject: [PATCH 15/18] update docstrings --- src/lightning_app/utilities/load_app.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index 6214f8907af8c..6b1344b746a01 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -19,8 +19,6 @@ def _prettifiy_exception(filepath: str): """Pretty print the exception that occurred when loading the app. - :param filepath: - :return: """ # we want to format the exception as if no frame was on top. exp, val, tb = sys.exc_info() @@ -37,8 +35,9 @@ def _prettifiy_exception(filepath: str): def load_app_from_file(filepath: str, raise_exception: bool = False) -> "LightningApp": """Load a LightningApp from a file. - :param filepath: The path to the file containing the LightningApp. - :param raise_exception: If True, raise an exception if the app cannot be loaded. + Arguments: + filepath: The path to the file containing the LightningApp. + raise_exception: If True, raise an exception if the app cannot be loaded. """ # Taken from StreamLit: https://github.com/streamlit/streamlit/blob/develop/lib/streamlit/script_runner.py#L313 From c7281382cdbf217061a719f81c9134e30a339153 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 31 Oct 2022 16:28:37 +0000 Subject: [PATCH 16/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/lightning_app/utilities/load_app.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index 6b1344b746a01..2182162f3e0c3 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -17,9 +17,7 @@ def _prettifiy_exception(filepath: str): - """Pretty print the exception that occurred when loading the app. - - """ + """Pretty print the exception that occurred when loading the app.""" # we want to format the exception as if no frame was on top. exp, val, tb = sys.exc_info() listing = traceback.format_exception(exp, val, tb) From 72656c874f821dd6b8629f22f40634a6f19bedff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Mon, 31 Oct 2022 17:50:04 +0100 Subject: [PATCH 17/18] fix flake8 error --- src/lightning_app/runners/cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 6adcb0eb48000..703cf65c56b48 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -470,7 +470,7 @@ def load_app_from_file(cls, filepath: str) -> "LightningApp": """This is meant to use only locally for cloud runtime.""" try: app = load_app_from_file(filepath, raise_exception=True) - except ModuleNotFoundError as e: + except ModuleNotFoundError: # this is very generic exception. logger.info("Could not load the app() locally. Starting the app directly on the cloud.") # we want to format the exception as if no frame was on top. From 8a7263d6f5b0ce9e705d39c544cb7d721059b2c1 Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Mon, 31 Oct 2022 18:15:11 +0100 Subject: [PATCH 18/18] Apply suggestions from code review Co-authored-by: Luca Antiga --- src/lightning_app/runners/cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning_app/runners/cloud.py b/src/lightning_app/runners/cloud.py index 703cf65c56b48..919f7548bc09c 100644 --- a/src/lightning_app/runners/cloud.py +++ b/src/lightning_app/runners/cloud.py @@ -472,7 +472,7 @@ def load_app_from_file(cls, filepath: str) -> "LightningApp": app = load_app_from_file(filepath, raise_exception=True) except ModuleNotFoundError: # this is very generic exception. - logger.info("Could not load the app() locally. Starting the app directly on the cloud.") + logger.info("Could not load the app locally. Starting the app directly on the cloud.") # we want to format the exception as if no frame was on top. exp, val, tb = sys.exc_info() listing = traceback.format_exception(exp, val, tb)