From e698203a686a966f2e6f46a704155d93bc4fbf30 Mon Sep 17 00:00:00 2001 From: mansy Date: Fri, 12 Aug 2022 12:35:49 +0200 Subject: [PATCH 1/4] fix install latest version of app/component --- src/lightning_app/cli/cmd_install.py | 7 ++++--- tests/tests_app/cli/test_cmd_install.py | 27 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/lightning_app/cli/cmd_install.py b/src/lightning_app/cli/cmd_install.py index f15567bd8470c..9c7b4c8a72a66 100644 --- a/src/lightning_app/cli/cmd_install.py +++ b/src/lightning_app/cli/cmd_install.py @@ -7,6 +7,7 @@ import sys import requests +from packaging.version import Version from lightning_app.core.constants import LIGHTNING_APPS_PUBLIC_REGISTRY, LIGHTNING_COMPONENT_PUBLIC_REGISTRY @@ -299,8 +300,8 @@ def _validate_name(name, resource_type, example): def _resolve_resource(registry_url, name, version_arg, resource_type): gallery_entries = [] try: - url = requests.get(registry_url) - data = json.loads(url.text) + response = requests.get(registry_url) + data = response.json() if resource_type == "app": gallery_entries = [a for a in data["apps"] if a["canDownloadSourceCode"]] @@ -328,7 +329,7 @@ def _resolve_resource(registry_url, name, version_arg, resource_type): entry = None if version_arg == "latest": - entry = entries[-1] + entry = max(entries, key=lambda app: Version(app["version"])) else: for e in entries: if e["version"] == version_arg: diff --git a/tests/tests_app/cli/test_cmd_install.py b/tests/tests_app/cli/test_cmd_install.py index 2d277ddb7790c..ec04be3f22dd7 100644 --- a/tests/tests_app/cli/test_cmd_install.py +++ b/tests/tests_app/cli/test_cmd_install.py @@ -212,6 +212,33 @@ def test_version_arg_app(tmpdir): assert result.exit_code == 0 +@mock.patch("lightning_app.cli.cmd_install.subprocess", mock.MagicMock()) +@mock.patch("lightning_app.cli.cmd_install.os.chdir", mock.MagicMock()) +@mock.patch("lightning_app.cli.cmd_install._show_install_app_prompt") +def test_install_resolve_latest_version(mock_show_install_app_prompt, tmpdir): + + app_name = "lightning/invideo" + runner = CliRunner() + with mock.patch("lightning_app.cli.cmd_install.requests.get") as get_api_mock: + get_api_mock.return_value.json.return_value = { + "apps": [ + { + "canDownloadSourceCode": True, + "version": "0.0.2", + "name": "lightning/invideo", + }, + { + "canDownloadSourceCode": True, + "version": "0.0.4", + "name": "lightning/invideo", + }, + ] + } + runner.invoke(lightning_cli.install_app, [app_name, "--yes"]) # no version specified so latest is installed + assert mock_show_install_app_prompt.called + assert mock_show_install_app_prompt.call_args[0][0]["version"] == "0.0.4" + + def test_proper_url_parsing(): name = "lightning/invideo" From e3180ff519c2f9b7a704987afd84e16e7ea32b91 Mon Sep 17 00:00:00 2001 From: mansy Date: Fri, 12 Aug 2022 12:45:13 +0200 Subject: [PATCH 2/4] Add changelog --- src/lightning_app/CHANGELOG.md | 2 +- src/lightning_app/cli/cmd_install.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index 2aa5c7cdd837c..af2ece628c79c 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -45,7 +45,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Fixed -- +- Resolved a bug where install command was not installing the latest version of app/component be default ([#14181](https://github.com/Lightning-AI/lightning/pull/14181)) ## [0.5.5] - 2022-08-9 diff --git a/src/lightning_app/cli/cmd_install.py b/src/lightning_app/cli/cmd_install.py index 9c7b4c8a72a66..8f0e45145e59a 100644 --- a/src/lightning_app/cli/cmd_install.py +++ b/src/lightning_app/cli/cmd_install.py @@ -1,4 +1,3 @@ -import json import logging import os import re From b88b526a5dcffc99a4eb0459e6796c79ea524a1a Mon Sep 17 00:00:00 2001 From: mansy Date: Fri, 12 Aug 2022 12:47:25 +0200 Subject: [PATCH 3/4] a better testcase --- tests/tests_app/cli/test_cmd_install.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/tests_app/cli/test_cmd_install.py b/tests/tests_app/cli/test_cmd_install.py index ec04be3f22dd7..0139bbc9c5501 100644 --- a/tests/tests_app/cli/test_cmd_install.py +++ b/tests/tests_app/cli/test_cmd_install.py @@ -232,6 +232,11 @@ def test_install_resolve_latest_version(mock_show_install_app_prompt, tmpdir): "version": "0.0.4", "name": "lightning/invideo", }, + { + "canDownloadSourceCode": True, + "version": "0.0.5", + "name": "another_app", + }, ] } runner.invoke(lightning_cli.install_app, [app_name, "--yes"]) # no version specified so latest is installed From 2f8a39530c9ba2ea2ad2438489e7dd8dcdc73f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Mon, 15 Aug 2022 05:12:10 -0400 Subject: [PATCH 4/4] Update src/lightning_app/CHANGELOG.md --- src/lightning_app/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index af2ece628c79c..5a88748832aa3 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -45,7 +45,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Fixed -- Resolved a bug where install command was not installing the latest version of app/component be default ([#14181](https://github.com/Lightning-AI/lightning/pull/14181)) +- Resolved a bug where the install command was not installing the latest version of an app/component by default ([#14181](https://github.com/Lightning-AI/lightning/pull/14181)) ## [0.5.5] - 2022-08-9