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
3 changes: 2 additions & 1 deletion src/lightning_app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [0.7.0] - 2022-10-19
## [0.7.0] - 2022-10-20

### Added

- Add `--secret` option to CLI to allow binding Secrets to app environment variables when running in the cloud ([#14612](https://github.com/Lightning-AI/lightning/pull/14612))
- Added support for adding descriptions to commands either through a docstring or the `DESCRIPTION` attribute ([#15193](https://github.com/Lightning-AI/lightning/pull/15193)
- Added option to add custom meta tags to the UI container ([#14915](https://github.com/Lightning-AI/lightning/pull/14915))
- Added support to pass a `LightningWork` to the `LightningApp` ([#15215](https://github.com/Lightning-AI/lightning/pull/15215)

### Changed

Expand Down
10 changes: 7 additions & 3 deletions src/lightning_app/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
class LightningApp:
def __init__(
self,
root: "lightning_app.LightningFlow",
root: "t.Union[lightning_app.LightningFlow, lightning_app.LightningWork]",
debug: bool = False,
info: frontend.AppInfo = None,
root_path: str = "",
Expand All @@ -62,8 +62,8 @@ def __init__(
the :class:`~lightning.app.core.flow.LightningFlow` provided.

Arguments:
root: The root LightningFlow component, that defines all the app's nested components, running infinitely.
It must define a `run()` method that the app can call.
root: The root ``LightningFlow`` or ``LightningWork`` component, that defines all the app's nested
components, running infinitely. It must define a `run()` method that the app can call.
debug: Whether to activate the Lightning Logger debug mode.
This can be helpful when reporting bugs on Lightning repo.
info: Provide additional info about the app which will be used to update html title,
Expand All @@ -89,6 +89,10 @@ def __init__(
"""

self.root_path = root_path # when running behind a proxy

if isinstance(root, lightning_app.LightningWork):
root = lightning_app.core.flow._RootFlow(root)

_validate_root_flow(root)
self._root = root

Expand Down
12 changes: 12 additions & 0 deletions src/lightning_app/core/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,15 @@ def configure_api(self):
under the ``/docs`` route.
"""
raise NotImplementedError


class _RootFlow(LightningFlow):
def __init__(self, work):
super().__init__()
self.work = work

def run(self):
self.work.run()

def configure_layout(self):
return [{"name": "Main", "content": self.work}]
18 changes: 18 additions & 0 deletions tests/tests_app/core/test_lightning_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from lightning_app.runners import MultiProcessRuntime
from lightning_app.storage import Path
from lightning_app.testing.helpers import EmptyFlow, EmptyWork, MockQueue
from lightning_app.testing.testing import LightningTestApp
from lightning_app.utilities.enum import WorkStageStatus
from lightning_app.utilities.proxies import ProxyWorkRun, WorkRunner

Expand Down Expand Up @@ -327,3 +328,20 @@ def run(self, *args, **kwargs):

w = Work()
w.run()


class WorkCounter(LightningWork):
def run(self):
pass


class LightningTestAppWithWork(LightningTestApp):
def on_before_run_once(self):
if self.root.work.has_succeeded:
return True
return super().on_before_run_once()


def test_lightning_app_with_work():
app = LightningTestAppWithWork(WorkCounter())
MultiProcessRuntime(app, start_server=False).dispatch()