Skip to content

Commit 5f524cc

Browse files
manskxlexierule
authored andcommitted
Fix install latest version of app/component (#14181)
* fix install latest version of app/component * Add changelog * a better testcase * Update src/lightning_app/CHANGELOG.md Co-authored-by: mansy <[email protected]> Co-authored-by: Adrian Wälchli <[email protected]> (cherry picked from commit 562d22f)
1 parent 1769345 commit 5f524cc

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

src/lightning_app/CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44

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

7+
8+
## [0.5.6] - 2022-08-DD
9+
10+
### Fixed
11+
12+
- 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))
13+
14+
715
## [0.5.5] - 2022-08-9
816

917
### Deprecated
@@ -17,7 +25,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1725
- Fixed Start Lightning App on Cloud if Repo Begins With Name "Lightning" ([#14025](https://github.com/Lightning-AI/lightning/pull/14025))
1826

1927

20-
2128
## [0.5.4] - 2022-08-01
2229

2330
### Changed

src/lightning_app/cli/cmd_install.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import logging
32
import os
43
import re
@@ -7,6 +6,7 @@
76
import sys
87

98
import requests
9+
from packaging.version import Version
1010

1111
from lightning_app.core.constants import LIGHTNING_APPS_PUBLIC_REGISTRY, LIGHTNING_COMPONENT_PUBLIC_REGISTRY
1212

@@ -299,8 +299,8 @@ def _validate_name(name, resource_type, example):
299299
def _resolve_resource(registry_url, name, version_arg, resource_type):
300300
gallery_entries = []
301301
try:
302-
url = requests.get(registry_url)
303-
data = json.loads(url.text)
302+
response = requests.get(registry_url)
303+
data = response.json()
304304

305305
if resource_type == "app":
306306
gallery_entries = [a for a in data["apps"] if a["canDownloadSourceCode"]]
@@ -328,7 +328,7 @@ def _resolve_resource(registry_url, name, version_arg, resource_type):
328328

329329
entry = None
330330
if version_arg == "latest":
331-
entry = entries[-1]
331+
entry = max(entries, key=lambda app: Version(app["version"]))
332332
else:
333333
for e in entries:
334334
if e["version"] == version_arg:

tests/tests_app/cli/test_cmd_install.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,38 @@ def test_version_arg_app(tmpdir):
212212
assert result.exit_code == 0
213213

214214

215+
@mock.patch("lightning_app.cli.cmd_install.subprocess", mock.MagicMock())
216+
@mock.patch("lightning_app.cli.cmd_install.os.chdir", mock.MagicMock())
217+
@mock.patch("lightning_app.cli.cmd_install._show_install_app_prompt")
218+
def test_install_resolve_latest_version(mock_show_install_app_prompt, tmpdir):
219+
220+
app_name = "lightning/invideo"
221+
runner = CliRunner()
222+
with mock.patch("lightning_app.cli.cmd_install.requests.get") as get_api_mock:
223+
get_api_mock.return_value.json.return_value = {
224+
"apps": [
225+
{
226+
"canDownloadSourceCode": True,
227+
"version": "0.0.2",
228+
"name": "lightning/invideo",
229+
},
230+
{
231+
"canDownloadSourceCode": True,
232+
"version": "0.0.4",
233+
"name": "lightning/invideo",
234+
},
235+
{
236+
"canDownloadSourceCode": True,
237+
"version": "0.0.5",
238+
"name": "another_app",
239+
},
240+
]
241+
}
242+
runner.invoke(lightning_cli.install_app, [app_name, "--yes"]) # no version specified so latest is installed
243+
assert mock_show_install_app_prompt.called
244+
assert mock_show_install_app_prompt.call_args[0][0]["version"] == "0.0.4"
245+
246+
215247
def test_proper_url_parsing():
216248

217249
name = "lightning/invideo"

0 commit comments

Comments
 (0)