From f53e4ad6bce063f8d4ba14177c450180c6230ef2 Mon Sep 17 00:00:00 2001 From: Ryan Clary <9618975+mrclary@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:17:31 -0700 Subject: [PATCH] Check previous releases for available asset if latest asset is not available. --- .../plugins/updatemanager/widgets/update.py | 2 +- spyder/plugins/updatemanager/workers.py | 79 +++++++++++-------- 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/spyder/plugins/updatemanager/widgets/update.py b/spyder/plugins/updatemanager/widgets/update.py index b1778110036..2a4c5bfa3b6 100644 --- a/spyder/plugins/updatemanager/widgets/update.py +++ b/spyder/plugins/updatemanager/widgets/update.py @@ -235,7 +235,7 @@ def _set_installer_path(self): asset_info = get_asset_info(self.latest_release) self.update_type = asset_info['update_type'] - dirname = osp.join(get_temp_dir(), 'updates', self.latest_release) + dirname = osp.join(get_temp_dir(), 'updates', str(self.latest_release)) self.installer_path = osp.join(dirname, asset_info['name']) self.installer_size_path = osp.join(dirname, "size") diff --git a/spyder/plugins/updatemanager/workers.py b/spyder/plugins/updatemanager/workers.py index 60a64b51597..81dbff7dbed 100644 --- a/spyder/plugins/updatemanager/workers.py +++ b/spyder/plugins/updatemanager/workers.py @@ -170,26 +170,10 @@ def __init__(self, stable_only): super().__init__() self.stable_only = stable_only self.latest_release = None - self.releases = None self.update_available = False self.error = None self.channel = None - def _check_update_available(self): - """Checks if there is an update available from releases.""" - # Filter releases - releases = self.releases.copy() - if self.stable_only: - # Only use stable releases - releases = [r for r in releases if not r.is_prerelease] - logger.debug(f"Available versions: {self.releases}") - - self.latest_release = max(releases) if releases else CURR_VER - self.update_available = CURR_VER < self.latest_release - - logger.debug(f"Update available: {self.update_available}") - logger.debug(f"Latest release: {self.latest_release}") - def start(self): """Main method of the worker.""" self.error = None @@ -223,26 +207,57 @@ def start(self): data = page.json() if url.endswith('releases'): # Github url - self.releases = [parse(item['tag_name']) for item in data] + releases = [parse(item['tag_name']) for item in data] else: # Conda url spyder_data = data['packages'].get('spyder') if spyder_data: - self.releases = [parse(spyder_data["version"])] - self.releases.sort() - - self._check_update_available() - - # Check if asset is available for download - if url.endswith('releases') and self.update_available: - asset_info = get_asset_info(self.latest_release) - page = requests.head(asset_info['url'], headers=headers) - _rate_limits(page) - if page.status_code == 404: - # The asset is not available - self.latest_release = CURR_VER - self.update_available = False - logger.debug(f"Asset is not available: {url}") + releases = [parse(spyder_data["version"])] + releases.sort() + + if self.stable_only: + # Only use stable releases + releases = [r for r in releases if not r.is_prerelease] + logger.debug(f"Available versions: {releases}") + + max_release = max(releases) if releases else CURR_VER + update_available = CURR_VER < max_release + + logger.debug(f"Update available: {update_available}") + logger.debug(f"Latest release: {max_release}") + + # Check if the asset is available for download. + # If the asset is not available, then check the next latest + # release, and so on until either a new asset is available or there + # is no update available. + if url.endswith('releases'): + asset_available = False + while update_available and not asset_available: + asset_info = get_asset_info(max_release) + page = requests.head(asset_info['url'], headers=headers) + _rate_limits(page) + if page.status_code == 302: + # The asset is found + logger.debug(f"Asset available for url: {url}") + asset_available = True + else: + # The asset is not available + logger.debug( + "Asset not available: " + f"{page.status_code} Client Error: {page.reason}" + f" for url: {url}" + ) + asset_available = False + releases.remove(max_release) + + max_release = max(releases) if releases else CURR_VER + update_available = CURR_VER < max_release + + logger.debug(f"Update available: {update_available}") + logger.debug(f"Latest release: {max_release}") + + self.latest_release = max_release + self.update_available = update_available except SSLError as err: error_msg = SSL_ERROR_MSG