Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lightning_app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Fixed

-
- 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
Expand Down
8 changes: 4 additions & 4 deletions src/lightning_app/cli/cmd_install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import logging
import os
import re
Expand All @@ -7,6 +6,7 @@
import sys

import requests
from packaging.version import Version

from lightning_app.core.constants import LIGHTNING_APPS_PUBLIC_REGISTRY, LIGHTNING_COMPONENT_PUBLIC_REGISTRY

Expand Down Expand Up @@ -299,8 +299,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"]]
Expand Down Expand Up @@ -328,7 +328,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:
Expand Down
32 changes: 32 additions & 0 deletions tests/tests_app/cli/test_cmd_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,38 @@ 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",
},
{
"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
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"
Expand Down