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 <mansy@lightning.ai> Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
This commit is contained in:
parent
48c23e5716
commit
562d22f0c8
|
@ -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
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
@ -7,6 +6,7 @@ import subprocess
|
|||
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 +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"]]
|
||||
|
@ -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:
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue