From dd83587102bf9650babf2af407af79d623934a84 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Fri, 9 Dec 2022 10:27:46 +0000 Subject: [PATCH] [App] Resolve run installation (#15974) --- src/lightning_app/cli/cmd_install.py | 15 +++++++++------ tests/tests_app/cli/test_cmd_install.py | 12 ++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/lightning_app/cli/cmd_install.py b/src/lightning_app/cli/cmd_install.py index 579a921179b4c..56c3d07b3d37f 100644 --- a/src/lightning_app/cli/cmd_install.py +++ b/src/lightning_app/cli/cmd_install.py @@ -101,7 +101,7 @@ def gallery_apps_and_components( except Exception: return None - entry, kind = _resolve_entry(app_or_component, version_arg) + entry, kind = _resolve_entry(name, version_arg) if kind == "app": # give the user the chance to do a manual install @@ -111,16 +111,19 @@ def gallery_apps_and_components( # run installation if requested _install_app_from_source(source_url, git_url, folder_name, cwd=cwd, overwrite=overwrite, git_sha=git_sha) - return os.path.join(os.getcwd(), folder_name, entry["appEntrypointFile"]) + return os.path.join(os.getcwd(), *entry["appEntrypointFile"].split("/")) elif kind == "component": # give the user the chance to do a manual install - git_url = _show_install_component_prompt(entry, app_or_component, org, yes_arg) - + source_url, git_url, folder_name, git_sha = _show_install_app_prompt( + entry, app_or_component, org, yes_arg, resource_type="component" + ) + if "@" in git_url: + git_url = git_url.split("git+")[1].split("@")[0] # run installation if requested - _install_component_from_source(git_url) + _install_app_from_source(source_url, git_url, folder_name, cwd=cwd, overwrite=overwrite, git_sha=git_sha) - return os.path.join(os.getcwd(), entry["appEntrypointFile"]) + return os.path.join(os.getcwd(), *entry["entrypointFile"].split("/")) return None diff --git a/tests/tests_app/cli/test_cmd_install.py b/tests/tests_app/cli/test_cmd_install.py index 2e2086348cb58..c11dd5fdd38c0 100644 --- a/tests/tests_app/cli/test_cmd_install.py +++ b/tests/tests_app/cli/test_cmd_install.py @@ -321,6 +321,18 @@ def test_install_app_shows_error(tmpdir): # os.chdir(cwd) +def test_app_and_component_gallery_app(monkeypatch): + monkeypatch.setattr(cmd_install, "_install_app_from_source", mock.MagicMock()) + path = cmd_install.gallery_apps_and_components("lightning/lightning-diffusion-component-api", True, "latest") + assert path == os.path.join(os.getcwd(), "diffusion2", "app.py") + + +def test_app_and_component_gallery_component(monkeypatch): + monkeypatch.setattr(cmd_install, "_install_app_from_source", mock.MagicMock()) + path = cmd_install.gallery_apps_and_components("lightning/lit-jupyter", True, "latest") + assert path == os.path.join(os.getcwd(), "app.py") + + @mock.patch.dict(os.environ, {"LIGHTNING_APP_REGISTRY": "https://TODO/other_non_PL_registry"}) def test_private_app_registry(): registry = cmd_install._resolve_app_registry()