-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[App] Introduce Commands #13602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[App] Introduce Commands #13602
Changes from all commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
63e80fc
update
tchaton 8c94042
update
tchaton 39e5036
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0b6c763
update
tchaton afb3371
Merge branch 'lightning_commands' of https://github.com/Lightning-AI/…
tchaton 608c4a6
update
tchaton 772d4a5
update
tchaton dca63de
update
tchaton 0091f4e
update
tchaton ee3f7ad
update
tchaton b06ec89
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 59661c2
update
tchaton c69ae80
Merge branch 'lightning_commands' of https://github.com/Lightning-AI/…
tchaton 239a879
update
tchaton 8551482
update
tchaton 2154520
update
tchaton 6c95cf5
update
tchaton 350d11e
update
tchaton 2846842
update
tchaton 5d80b33
Merge branch 'master' into lightning_commands
tchaton 602de9c
working poc
tchaton ad51386
update
tchaton e678cba
wip
tchaton bc9b2f5
update
tchaton 870b9aa
update
tchaton c1de86b
update
tchaton 9d7eb18
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3c3192f
update
tchaton a000bc3
Merge branch 'lightning_commands' of https://github.com/Lightning-AI/…
tchaton 42fe030
update
tchaton b796082
update
tchaton 63a57f0
update
tchaton 4ed8759
update
tchaton 19ffd9c
update
tchaton e78e43b
update
tchaton 0f8b11f
update
tchaton 119b312
update
tchaton 88e6c13
update
tchaton aa0b60b
Apply suggestions from code review
Borda 3e4fa95
update
tchaton a462a32
update
tchaton ddad86c
update
tchaton 7882a9e
update
tchaton aa7e797
update
tchaton 66f62d2
Merge branch 'master' into lightning_commands
tchaton 27d0ca8
update
tchaton bd6e449
update
tchaton 73a6a3f
update
tchaton 2e785bb
update
tchaton 8c6849d
Merge branch 'master' into lightning_commands
tchaton deb1c40
update
tchaton fa04ab6
Merge branch 'lightning_commands' of https://github.com/Lightning-AI/…
tchaton 78dbd10
update
tchaton da353a7
update
tchaton 05fc114
update
tchaton 4f00118
update
tchaton 4fee4ca
update
tchaton 8867005
update
tchaton 6e11661
update
tchaton f628641
Update src/lightning_app/CHANGELOG.md
tchaton bf237a4
update
tchaton a04bac0
Merge branch 'lightning_commands' of https://github.com/Lightning-AI/…
tchaton 275e3f0
Merge branch 'master' into lightning_commands
tchaton 6d011e7
update
tchaton fc47f84
Merge branch 'lightning_commands' of https://github.com/Lightning-AI/…
tchaton 4485cf9
update
tchaton 5f5c8bf
update
tchaton 7e6d09b
update
tchaton 30e84e8
update
tchaton d40a228
Merge branch 'master' into lightning_commands
tchaton 1abef07
update
tchaton f11f0b7
Merge branch 'lightning_commands' of https://github.com/Lightning-AI/…
tchaton 5525fbf
Merge branch 'master' into lightning_commands
tchaton 495c9f0
update
tchaton 51f6999
Merge branch 'lightning_commands' of https://github.com/Lightning-AI/…
tchaton 1d61f14
update
tchaton 1fb95bc
Merge branch 'master' into lightning_commands
tchaton 5b6434d
update
tchaton 99767c3
Merge branch 'master' into lightning_commands
tchaton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| name: app-commands |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from command import CustomCommand, CustomConfig | ||
tchaton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| from lightning import LightningFlow | ||
| from lightning_app.core.app import LightningApp | ||
|
|
||
|
|
||
| class ChildFlow(LightningFlow): | ||
| def trigger_method(self, name: str): | ||
| print(f"Hello {name}") | ||
|
|
||
| def configure_commands(self): | ||
| return [{"nested_trigger_command": self.trigger_method}] | ||
tchaton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class FlowCommands(LightningFlow): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.names = [] | ||
| self.child_flow = ChildFlow() | ||
|
|
||
| def run(self): | ||
| if len(self.names): | ||
| print(self.names) | ||
|
|
||
| def trigger_without_client_command(self, name: str): | ||
| self.names.append(name) | ||
|
|
||
| def trigger_with_client_command(self, config: CustomConfig): | ||
| self.names.append(config.name) | ||
|
|
||
| def configure_commands(self): | ||
| commands = [ | ||
| {"trigger_without_client_command": self.trigger_without_client_command}, | ||
| {"trigger_with_client_command": CustomCommand(self.trigger_with_client_command)}, | ||
| ] | ||
| return commands + self.child_flow.configure_commands() | ||
|
|
||
|
|
||
| app = LightningApp(FlowCommands()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from argparse import ArgumentParser | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
| from lightning.app.utilities.commands import ClientCommand | ||
|
|
||
|
|
||
| class CustomConfig(BaseModel): | ||
| name: str | ||
|
|
||
|
|
||
| class CustomCommand(ClientCommand): | ||
| def run(self): | ||
| parser = ArgumentParser() | ||
| parser.add_argument("--name", type=str) | ||
| args = parser.parse_args() | ||
| self.invoke_handler(config=CustomConfig(name=args.name)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, are this env. var described somewhere?