Skip to content

Commit

Permalink
Check previous releases for available asset if latest asset is not av…
Browse files Browse the repository at this point in the history
…ailable.
  • Loading branch information
mrclary committed Sep 27, 2024
1 parent 104e689 commit f53e4ad
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
2 changes: 1 addition & 1 deletion spyder/plugins/updatemanager/widgets/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
79 changes: 47 additions & 32 deletions spyder/plugins/updatemanager/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f53e4ad

Please sign in to comment.