Skip to content

Commit

Permalink
get latest msi version from json
Browse files Browse the repository at this point in the history
  • Loading branch information
Ying Chen committed Feb 19, 2024
1 parent 0601b8b commit 1dc9c94
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/promptflow/promptflow/_cli/_pf/_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ def upgrade_version(args):
from packaging.version import parse

from promptflow._constants import _ENV_PF_INSTALLER, CLI_PACKAGE_NAME
from promptflow._utils.version_hint_utils import get_latest_version_from_pypi
from promptflow._utils.version_hint_utils import get_latest_version
from promptflow._version import VERSION as local_version

latest_version = get_latest_version_from_pypi(CLI_PACKAGE_NAME)
installer = os.getenv(_ENV_PF_INSTALLER) or ""
installer = installer.upper()
print(f"installer: {installer}")
latest_version = get_latest_version(CLI_PACKAGE_NAME, installer=installer)
if not latest_version:
logger.warning("Failed to get the latest prompt flow version.")
return
Expand All @@ -53,9 +56,6 @@ def upgrade_version(args):

yes = args.yes
exit_code = 0
installer = os.getenv(_ENV_PF_INSTALLER) or ""
installer = installer.upper()
print(f"installer: {installer}")
latest_version_msg = (
"Upgrading prompt flow CLI version to {}.".format(latest_version)
if yes
Expand All @@ -82,7 +82,7 @@ def upgrade_version(args):
"pip",
"install",
"--upgrade",
"promptflow[azure,executable,azureml-serving]",
"promptflow[azure,executable,azureml-serving,executor-service]",
"-vv",
"--disable-pip-version-check",
"--no-cache-dir",
Expand Down
30 changes: 18 additions & 12 deletions src/promptflow/promptflow/_utils/version_hint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
import logging

from promptflow._constants import (
LAST_HINT_TIME,
LAST_CHECK_TIME,
PF_VERSION_CHECK,
CLI_PACKAGE_NAME,
HINT_INTERVAL_DAY,
CURRENT_VERSION,
GET_PYPI_INTERVAL_DAY,
HINT_INTERVAL_DAY,
LAST_CHECK_TIME,
LAST_HINT_TIME,
LATEST_VERSION,
CURRENT_VERSION,
PF_VERSION_CHECK,
)
from promptflow._sdk._constants import HOME_PROMPT_FLOW_DIR


HINT_ACTIVITY_NAME = [
"pf.flows.test",
"pf.runs.create_or_update",
Expand All @@ -44,20 +43,26 @@ def dump_cached_versions(cached_versions):
json.dump(cached_versions, f)


def get_latest_version_from_pypi(package_name):
pypi_url = f"https://pypi.org/pypi/{package_name}/json"
def get_latest_version(package_name, installer="PIP"):
if installer == "MSI":
url = "https://promptflowartifact.blob.core.windows.net/msi-installer/latest_version.json"
else:
url = f"https://pypi.org/pypi/{package_name}/json"
try:
import requests

response = requests.get(pypi_url, timeout=3)
response = requests.get(url, timeout=3)
if response.status_code == 200:
data = response.json()
latest_version = data["info"]["version"]
if installer == "MSI":
latest_version = data[package_name]
else:
latest_version = data["info"]["version"]
return latest_version
else:
return None
except Exception as ex: # pylint: disable=broad-except
logger.debug(f"Failed to get the latest version from '{pypi_url}'. {str(ex)}")
logger.debug(f"Failed to get the latest version from '{url}'. {str(ex)}")
return None


Expand All @@ -73,7 +78,8 @@ def check_latest_version():
if last_check_time is None or (
datetime.datetime.now() > last_check_time + datetime.timedelta(days=GET_PYPI_INTERVAL_DAY)
):
version = get_latest_version_from_pypi(CLI_PACKAGE_NAME)
# For hint, we can't know pfazure installed way for now, so we only check the latest version from pypi.
version = get_latest_version(CLI_PACKAGE_NAME)
if version is not None:
cached_versions[LATEST_VERSION] = version
cached_versions[LAST_CHECK_TIME] = str(datetime.datetime.now())
Expand Down

0 comments on commit 1dc9c94

Please sign in to comment.