-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Introduce lightning connect #14183
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
Introduce lightning connect #14183
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
2c8b6be
update
tchaton 8dbdf51
update
tchaton e1ad9ac
update
tchaton fe7e71f
Merge branch 'master' into connect
tchaton 389dcba
update
tchaton f495840
Merge branch 'connect' of https://github.com/Lightning-AI/lightning i…
tchaton 8224eb0
update
tchaton 85198d5
udpate
tchaton 036a7cb
update
tchaton 725f05c
update
tchaton cd3f073
update
tchaton 30dabca
update
tchaton 4023f0b
update
tchaton 7c61571
Merge branch 'add_missing_docs' into connect
tchaton 7f21a36
update
tchaton ff370a8
update
tchaton 4a0f57f
Update docs/source-app/workflows/build_command_line_interface/cli.rst
tchaton 957c2c5
update
tchaton 4dd371f
update
tchaton a5bfbcc
Merge branch 'connect' of https://github.com/Lightning-AI/lightning i…
tchaton 5af164c
update
tchaton 19334e5
update
tchaton 98b0897
update
tchaton e70e38f
Merge branch 'add_missing_docs' into connect
tchaton d5e725d
update
tchaton 8527c8f
update
tchaton ddd0ce1
update
tchaton 08b324d
update
tchaton 0f9a8c7
update
tchaton e169f32
update
tchaton 798b525
update
tchaton 0a21ff2
Merge branch 'add_missing_docs' into connect
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
27 changes: 0 additions & 27 deletions
27
docs/source-app/workflows/build_command_line_interface/post_example.py
This file was deleted.
Oops, something went wrong.
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
Empty file.
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,94 @@ | ||
import os | ||
import sys | ||
from typing import Dict, Optional | ||
|
||
import requests | ||
|
||
from lightning_app.cli.commands.connection import _resolve_command_path | ||
from lightning_app.utilities.cli_helpers import _retrieve_application_url_and_available_commands | ||
from lightning_app.utilities.commands.base import _download_command | ||
from lightning_app.utilities.enum import OpenAPITags | ||
|
||
|
||
def _run_app_command(app_name: str, app_id: Optional[str]): | ||
"""Execute a function in a running App from its name.""" | ||
# 1: Collect the url and comments from the running application | ||
url, api_commands, _ = _retrieve_application_url_and_available_commands(app_id) | ||
if url is None or api_commands is None: | ||
raise Exception("We couldn't find any matching running App.") | ||
|
||
if not api_commands: | ||
raise Exception("This application doesn't expose any commands yet.") | ||
|
||
full_command = "_".join(sys.argv) | ||
|
||
has_found = False | ||
for command in list(api_commands): | ||
if command in full_command: | ||
has_found = True | ||
break | ||
|
||
if not has_found: | ||
tchaton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise Exception(f"The provided command isn't available in {list(api_commands)}") | ||
|
||
# 2: Send the command from the user | ||
metadata = api_commands[command] | ||
|
||
# 3: Execute the command | ||
if metadata["tag"] == OpenAPITags.APP_COMMAND: | ||
_handle_command_without_client(command, metadata, url) | ||
else: | ||
_handle_command_with_client(command, metadata, app_name, app_id, url) | ||
|
||
if sys.argv[-1] != "--help": | ||
print("Your command execution was successful.") | ||
|
||
|
||
def _handle_command_without_client(command: str, metadata: Dict, url: str) -> None: | ||
# TODO: Improve what is current supported | ||
supported_params = list(metadata["parameters"]) | ||
if "--help" == sys.argv[-1]: | ||
print(f"Usage: lightning {command} [ARGS]...") | ||
print(" ") | ||
print("Options") | ||
for param in supported_params: | ||
print(f" {param}: Add description") | ||
return | ||
|
||
provided_params = [param.replace("--", "") for param in sys.argv[2:]] | ||
|
||
if any("=" not in param for param in provided_params): | ||
raise Exception("Please, use --x=y syntax when providing the command arguments.") | ||
tchaton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for param in provided_params: | ||
if param.split("=")[0] not in supported_params: | ||
raise Exception(f"Some arguments need to be provided. The keys are {supported_params}.") | ||
tchaton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
# TODO: Encode the parameters and validate their type. | ||
query_parameters = "&".join(provided_params) | ||
resp = requests.post(url + f"/command/{command}?{query_parameters}") | ||
assert resp.status_code == 200, resp.json() | ||
|
||
|
||
def _handle_command_with_client(command: str, metadata: Dict, app_name: str, app_id: Optional[str], url: str): | ||
debug_mode = bool(int(os.getenv("DEBUG", "0"))) | ||
|
||
if app_name == "localhost": | ||
target_file = metadata["cls_path"] | ||
else: | ||
target_file = _resolve_command_path(command) if debug_mode else _resolve_command_path(command) | ||
|
||
if debug_mode: | ||
print(target_file) | ||
|
||
client_command = _download_command( | ||
command, | ||
metadata["cls_path"], | ||
metadata["cls_name"], | ||
app_id, | ||
debug_mode=debug_mode, | ||
target_file=target_file if debug_mode else _resolve_command_path(command), | ||
) | ||
client_command._setup(command_name=command, app_url=url) | ||
sys.argv = sys.argv[len(command.split("_")) :] | ||
client_command.run() |
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.
Uh oh!
There was an error while loading. Please reload this page.