Skip to content

Commit

Permalink
Restore using defaults channel for checking for updates when Spyder i…
Browse files Browse the repository at this point in the history
…s installed using defaults channel.

Because the defaults channel is usually very far behind the Github releases, this prevents users from being spammed for updates that are not available on the defaults channel.
  • Loading branch information
mrclary committed Jul 16, 2024
1 parent 460de25 commit 2795868
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
15 changes: 12 additions & 3 deletions spyder/plugins/updatemanager/tests/test_update_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ def worker():
# ---- Test WorkerUpdate

@pytest.mark.parametrize("version", ["1.0.0", "1000.0.0"])
def test_updates(qtbot, mocker, version, caplog):
@pytest.mark.parametrize(
"channel", [
("pkgs/main", "https://repo.anaconda.com/pkgs/main"),
("conda-forge", "https://conda.anaconda.org/conda-forge"),
]
)
def test_updates(qtbot, mocker, caplog, version, channel):
"""
Test whether or not we offer updates for our installers according to the
current Spyder version.
Test whether or not we offer updates according to the current Spyder
version and package installation channel.
Uses UpdateManagerWidget in order to also test QThread.
"""
Expand All @@ -44,6 +50,9 @@ def test_updates(qtbot, mocker, version, caplog):
UpdateManagerWidget, "start_update", new=lambda x: None
)
mocker.patch.object(workers, "__version__", new=version)
mocker.patch.object(
workers, "get_spyder_conda_channel", return_value=channel
)

with caplog.at_level(logging.DEBUG, logger='spyder.plugins.updatemanager'):
# Capture >=DEBUG logging messages for spyder.plugins.updatemanager
Expand Down
19 changes: 17 additions & 2 deletions spyder/plugins/updatemanager/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# Local imports
from spyder import __version__
from spyder.config.base import _, is_stable_version, running_in_ci
from spyder.config.utils import is_anaconda
from spyder.utils.conda import get_spyder_conda_channel
from spyder.utils.programs import check_version

# Logger setup
Expand Down Expand Up @@ -117,7 +119,6 @@ def __init__(self, stable_only):
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."""
Expand Down Expand Up @@ -146,6 +147,14 @@ def start(self):
error_msg = None
url = 'https://api.github.com/repos/spyder-ide/spyder/releases'

# If Spyder is installed from defaults channel (pkgs/main), then use
# that channel to get updates. The defaults channel can be far behind
# our latest release
if is_anaconda():
channel, channel_url = get_spyder_conda_channel()
if channel == "pkgs/main":
url = channel_url + '/channeldata.json'

headers = {}
token = os.getenv('GITHUB_TOKEN')
if running_in_ci() and token:
Expand All @@ -158,10 +167,16 @@ def start(self):
page.raise_for_status()

data = page.json()
if self.releases is None:
if url.endswith('releases'):
# Github url
self.releases = [
item['tag_name'].replace('v', '') for item in data
]
else:
# Conda url
spyder_data = data['packages'].get('spyder')
if spyder_data:
self.releases = [spyder_data["version"]]
self.releases.sort(key=parse)

self._check_update_available()
Expand Down

0 comments on commit 2795868

Please sign in to comment.