|
4 | 4 | import string |
5 | 5 | import sys |
6 | 6 | import time |
| 7 | +import traceback |
7 | 8 | from dataclasses import dataclass |
8 | 9 | from pathlib import Path |
9 | 10 | from typing import Any, Callable, List, Optional, Union |
|
60 | 61 | from lightning_app.utilities.app_helpers import Logger |
61 | 62 | from lightning_app.utilities.cloud import _get_project |
62 | 63 | from lightning_app.utilities.dependency_caching import get_hash |
| 64 | +from lightning_app.utilities.load_app import _prettifiy_exception, load_app_from_file |
63 | 65 | from lightning_app.utilities.packaging.app_config import AppConfig, find_config_file |
64 | 66 | from lightning_app.utilities.packaging.lightning_utils import _prepare_lightning_wheels_and_requirements |
65 | 67 | from lightning_app.utilities.secrets import _names_to_ids |
@@ -463,6 +465,30 @@ def _project_has_sufficient_credits(self, project: V1Membership, app: Optional[L |
463 | 465 |
|
464 | 466 | return balance >= 1 |
465 | 467 |
|
| 468 | + @classmethod |
| 469 | + def load_app_from_file(cls, filepath: str) -> "LightningApp": |
| 470 | + """This is meant to use only locally for cloud runtime.""" |
| 471 | + try: |
| 472 | + app = load_app_from_file(filepath, raise_exception=True) |
| 473 | + except ModuleNotFoundError: |
| 474 | + # this is very generic exception. |
| 475 | + logger.info("Could not load the app locally. Starting the app directly on the cloud.") |
| 476 | + # we want to format the exception as if no frame was on top. |
| 477 | + exp, val, tb = sys.exc_info() |
| 478 | + listing = traceback.format_exception(exp, val, tb) |
| 479 | + # remove the entry for the first frame |
| 480 | + del listing[1] |
| 481 | + from lightning_app.testing.helpers import EmptyFlow |
| 482 | + |
| 483 | + # Create a mocking app. |
| 484 | + app = LightningApp(EmptyFlow()) |
| 485 | + |
| 486 | + except FileNotFoundError as e: |
| 487 | + raise e |
| 488 | + except Exception: |
| 489 | + _prettifiy_exception(filepath) |
| 490 | + return app |
| 491 | + |
466 | 492 |
|
467 | 493 | def _create_mount_drive_spec(work_name: str, mount: Mount) -> V1LightningworkDrives: |
468 | 494 | if mount.protocol == "s3://": |
|
0 commit comments